LazyInitializationException in AbstractCollectionMapper
marx3 Oct 21, 2013 4:22 AMHello
I've set in persistence.xml:
<property name="org.hibernate.envers.global_with_modified_flag" value="true" />
I've started database from scratch.
Now my application in some places (when trying to persist Set) throws LazyInitializationException. It's in method org.hibernate.envers.entities.mapper.relation.AbstractCollectionMapper.mapCollectionChanges
in line: added.addAll(newCollection);
While I use JBoss 7.2.0, i've tried with latest stable Hibernate 4.2.6 (I've exchanged module) but it isn't fixed.
So I downloaded sources and tried to debug and fix it myself.
While in debug I see sometimes collection comes uninitialized. It's PersistentSet.
Hibernate.isInitialized(newColl) returns false.
1) I've tried to use
if (newColl instanceof AbstractPersistentCollection) {
AbstractPersistentCollection ps = (AbstractPersistentCollection) newColl;
session.initializeCollection(ps, true);
}
and got and error:
10:03:10,654 ERROR [org.hibernate.AssertionFailure] (http-localhost/127.0.0.1:8080-1) HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.NullPointerException
10:03:10,654 WARN [com.arjuna.ats.arjuna] (http-localhost/127.0.0.1:8080-1) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff0a01030e:-2ad659dd:5264df69:7b, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@4018f866 >: org.hibernate.AssertionFailure: Unable to perform beforeTransactionCompletion callback
at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:705) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:321) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:613) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:122) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.2.6.Final.jar:4.2.6.Final]
2) I've tried
if (newColl instanceof AbstractPersistentCollection) {
AbstractPersistentCollection ps = (AbstractPersistentCollection) newColl;
Hibernate.initialize(ps);
}
Error says collection is not yet connected with any session
3) This PersistentSet isn't proxy so I can't use proxy to initialize itself.
Any idea how can I initialize lazy collection in this place?