When using a query with the MongoDB based parser backend, I'm getting the following exception upon the commit of the container-managed transaction:
Caused by: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions: [org.hibernate.ogm.hiking.model.Hike.sections#1]
at org.hibernate.collection.internal.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:635) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.WrapVisitor.processCollection(WrapVisitor.java:66) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:121) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.WrapVisitor.processValue(WrapVisitor.java:125) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:76) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.DefaultFlushEntityEventListener.wrapCollections(DefaultFlushEntityEventListener.java:220) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:157) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:231) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:102) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:55) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.ogm.service.impl.FlushBatchManagerEventListener.delegate(FlushBatchManagerEventListener.java:48) [hibernate-ogm-core-4.1.0-SNAPSHOT.jar:4.1.0-SNAPSHOT]
at org.hibernate.ogm.service.impl.FlushBatchManagerEventListener.delegate(FlushBatchManagerEventListener.java:35) [hibernate-ogm-core-4.1.0-SNAPSHOT.jar:4.1.0-SNAPSHOT]
at org.hibernate.ogm.service.impl.BatchManagerEventListener.onEvent(BatchManagerEventListener.java:55) [hibernate-ogm-core-4.1.0-SNAPSHOT.jar:4.1.0-SNAPSHOT]
at org.hibernate.ogm.service.impl.FlushBatchManagerEventListener.onFlush(FlushBatchManagerEventListener.java:43) [hibernate-ogm-core-4.1.0-SNAPSHOT.jar:4.1.0-SNAPSHOT]
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:110) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
I believe the reason is that we pass the OgmSession instead of the underlying SessionImpl into OgmLoader from within MongoDBQueryImpl$ObjectLoadingIterator#getAsManagedEntity(). The exception then is caused by comparing the OgmSession and SessionImpl in AbstractPersistentCollection#setCurrentSession().
|