Hi all,
I encounter a problem in getting ConcurrentModificationException when there is more than 1 sessions opened concurrently:.
Code:
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:373)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:392)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:391)
at org.hibernate.util.IdentityMap.entryArray(IdentityMap.java:228)
at org.hibernate.util.IdentityMap.concurrentEntries(IdentityMap.java:89)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:205)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
...
I am coding against JPA API that EntityManager is referred to manipulate objects. Corresponding entityManager is stored in thread local that its session as well as the persistence context should be threadsafe.
However, there are something weird that I found some debug messages from hibernate on child collection initialization about the parent objects retrieved from thread A appeared in thread B makes me believe that corresponding collection initialization was done under thread B which is not expected because thread A and thread B is working on independent hierarchy of objects. And that's why causing the ConcurrentModificationException when thread B is trying to flush its own.
Does anyone offer me some helps on it as I have being working on it for days but still no clue?