what should i do to prevent javautilconcurrentmodificationexception?

You are replacing the value of books with another list then the loop tries to append the new list books into itself – hence ConcurrentModificationException.

Assuming that getResultList() returns a List all you need to do is append results directly to books without re-assignment:

books.addAll(session.createQuery("from Book").getResultList());

// books = session.createQuery("from Book").getResultList();
// for(Book book: books) {
//         books.add(book);
// }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top