Hi.
Our application is suffering several intermittent hibernate exceptions, mainly these:
- Collection processed twice by flush
- Found shared references to a collection
- Flush during cascade is dangerous
It happens only if you are working with a slow server and you load a lot of entities to the memory.
To make thing worse, problem is not easy to reproduce. Sometimes the system can survive 30 selenium tests, sometimes it fails just after a few requests.
It always happens on flush (usually invoked by JPA query). We use Jboss 4.2.2, Seam 2.1.1 with Extended Persistence and EJB3.
One of the main suspects is a circular reference in entities schema. Studying hibernate code shows that these exceptions are thrown mainly when a collection is processed twice.
Could you please have a look on the part of class schema and make a judgement: can it be a reason for having intermittent hibernate exceptions?
All relations are unidirectional OneToMany or ManyToOne.
The typical example of stacktrace can be:
Code:
Caused by: org.hibernate.HibernateException: Found shared references to a collection: D.Es
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:163)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:138)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:516)
It also happens for C.Fs and many others.
Another suspect is any timing or multi-threading issue.
Can anybody put some light on it? Is there any technique of solving such a problem?
Thanks in advance,
Jan