sakra sakra - 1 year ago 91
Java Question

ConcurrentModificationException upon committing transaction with Hibernate

In our application we have upgraded from Hibernate 3.5.6-final to 4.2.21.Final and now we are getting a

when a database transaction is committed:

java.util.ConcurrentModificationException: null
at java.util.ArrayList$Itr.checkForComodification(
at java.util.ArrayList$
at org.hibernate.engine.spi.ActionQueue.executeActions(
at org.hibernate.engine.spi.ActionQueue.executeActions(
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(
at org.hibernate.internal.SessionImpl.flush(
at org.hibernate.internal.SessionImpl.managedFlush(
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(

Is this a known issue with Hibernate 4.2?

Answer Source

The exception turned out to be caused by a problem with a Hibernate custom constraint validator we use. The validator's isValid was running a Hibernate criteria query. The query triggered a Hibernate session flush which resulted in the ConcurrentModificationException. We fixed the problem by temporarily disabling auto flush in the isValid method:

public boolean isValid(Object object, final ConstraintValidatorContext c) {
   try {
   } finally {

The problem may also manifest itself as a StackOverflowError.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download