Hibernate version: 3.2.5.ga
Code between sessionFactory.openSession() and session.close():
Caused by: org.hibernate.HibernateException: Found shared references to a collection: library.impl.LibraryImpl.books
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.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
Name and version of the database you are using: Oracle11g
When we query our database for any children of the LibraryImpl (ex: LibrayImpl.employees), we sometime get the exception above. But this exception occurs only when our application has multithread querying and persisting object to the database. When run in single thread, no exception occurs.
I don't understand why this exception occurs at query time.
Also :
The collection LibraryImpl.books is empty for all the instance of LibraryImpl in the datase. Why would we have a shared reference on a empty list set once by the constructor of the LibraryImpl?
We use Enhanced.id.SequenceStyleGenerator with increment-by set to 200. As a test I subclassed SequenceStyleGenerator and added the synchronized key word. I still randomly get the exception.
This is not the solution but problems goes away with this collection setter:
Code:
public void setBooks(List<Book> books)
{
this.books = new ArrayList<Book>(books);
}
We reviewed our model and there is no issue related to this post:
http://forum.hibernate.org/viewtopic.php?p=2273553
Anyone has a clue of what could be going on?