Hi there,
using bytecode enhancement with enableDirtyTracking=true and enabled second level cache, I'm encountering lazy init exceptions when the enhanced codes tries to clear the dirty attributes:
{noformat} org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java: 582 589 ) at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java: 574 581 ) at org.hibernate.collection.internal.AbstractPersistentCollection.access$200(AbstractPersistentCollection.java:55) at org.hibernate.collection.internal.AbstractPersistentCollection$1.doWork(AbstractPersistentCollection.java: 165 172 ) at org.hibernate.collection.internal.AbstractPersistentCollection$1.doWork(AbstractPersistentCollection.java: 146 153 ) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java: 247 254 ) at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java: 145 152 ) at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:143) at com models . sobis common . jaf security . model JafSid . security $$_hibernate_removeDirtyFields(JafSid . sid java) at models . common.security. JafSid.$$_hibernate_clearDirtyCollectionNames(JafSid.java) at com models . sobis common . jaf.model. security. sid. JafSid.$$_hibernate_clearDirtyAttributes(JafSid.java) at org.hibernate.tuple.entity.PojoEntityTuplizer.afterInitialize(PojoEntityTuplizer.java:297) at org.hibernate.persister.entity.AbstractEntityPersister.afterInitialize(AbstractEntityPersister.java: 4659 4788 ) at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java: 284 287 ) at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java: 128 129 ) at org.hibernate.loader. Loader plan . initializeEntitiesAndCollections exec.process.internal.AbstractRowReader.performTwoPhaseLoad ( Loader AbstractRowReader .java: 1152 238 ) at org.hibernate.loader. Loader plan . processResultSet exec.process.internal.AbstractRowReader.finishUp ( Loader AbstractRowReader .java: 1011 209 ) at org.hibernate.loader. Loader plan . doQuery exec.process.internal.ResultSetProcessorImpl.extractResults ( Loader ResultSetProcessorImpl .java: 949 133 ) at org.hibernate.loader. Loader plan . doQueryAndInitializeNonLazyCollections exec.internal.AbstractLoadPlanBasedLoader.executeLoad ( Loader AbstractLoadPlanBasedLoader .java: 341 122 ) at org.hibernate.loader. Loader plan . doList exec.internal.AbstractLoadPlanBasedLoader.executeLoad ( Loader AbstractLoadPlanBasedLoader .java: 2692 86 ) at org.hibernate.loader. Loader entity . doList plan.AbstractLoadPlanBasedEntityLoader.load ( Loader AbstractLoadPlanBasedEntityLoader .java: 2675 185 ) at org.hibernate. loader persister . Loader entity . listIgnoreQueryCache AbstractEntityPersister.load ( Loader AbstractEntityPersister .java: 2507 4226 ) at org.hibernate. loader event . Loader internal . list DefaultLoadEventListener.loadFromDatasource ( Loader DefaultLoadEventListener .java: 2502 509 ) at org.hibernate. loader event . criteria internal . CriteriaLoader DefaultLoadEventListener . list doLoad ( CriteriaLoader DefaultLoadEventListener .java: 109 479 ) at org.hibernate. event. internal. SessionImpl DefaultLoadEventListener . list load ( SessionImpl DefaultLoadEventListener .java: 1897 220 ) at org.hibernate. event. internal. CriteriaImpl DefaultLoadEventListener . list proxyOrLoad ( CriteriaImpl DefaultLoadEventListener .java: 370 263 ) at com org . sobis hibernate . jaf event . tests internal . setup DefaultLoadEventListener . DatabasePopulation.startBasicSetup doOnLoad ( DatabasePopulation DefaultLoadEventListener .java:122) {noformat} This error always happens after clearing the persistence context at org.hibernate.event.internal.DefaultLoadEventListener.onLoad ( either manually or when doing a commit) when the authority is reloaded: {code: DefaultLoadEventListener. java } Authority a = new Authority( :90 ) ; JafSid sid = new JafSid() at org . setSid("sid!"); sid hibernate . setRelatedEntity(a); sid internal . setClassType("type!"); a SessionImpl . setClassType fireLoad ( "type"); a SessionImpl . setSid(sid java:1255 ) ; a at org . setAuthority("name"); hibernate.internal.SessionImpl.access $ session 1900 ( ) SessionImpl . save(a java:207 ) ; at org.hibernate.internal.SessionImpl $ session() IdentifierLoadAccessImpl . flush doLoad ( SessionImpl.java:2867 ) ; at org.hibernate.internal.SessionImpl $ session() IdentifierLoadAccessImpl . clear load ( SessionImpl.java:2841 ) ; //throws exception in next line! LOGGER at org . error hibernate.internal.SessionImpl.get ( "auth SessionImpl.java : {}", $session( 1091 ) at org . get(Authority hibernate . class, a bugs . getId TestCase.lambda$hhh12425$0 ( TestCase.java:26 ) )); {code}
where {code:java} @Entity public class Authority extends SidEntity<BOUser> {
( at org . hibernate . bugs . ) } {code} where SidEntity is {code:java} @Entity @Table AbstractTestCase.doInOpenTransaction ( name = SidEntity AbstractTestCase . TABLE java:51 ) public abstract class SidEntity<BO extends BOSidEntity<? extends SidEntity<BO>>> extends Base<BO> { ( at org . hibernate . bugs . TestCase.hhh12425(TestCase.java:17 ) private JafSid sid; ( at sun . reflect . NativeMethodAccessorImpl . invoke0(Native Method ) @OneToOne(mappedBy = JafSid at sun . RELATED_ENTITY, optional = false, fetch = FetchType reflect . EAGER, orphanRemoval = true) @IndexedEmbedded NativeMethodAccessorImpl.invoke ( depth = 1, prefix = SID + JSONFieldDefinition NativeMethodAccessorImpl . MODEL_SUFFIX java:62 ) @Cascade at sun.reflect.DelegatingMethodAccessorImpl.invoke ( CascadeType DelegatingMethodAccessorImpl . ALL java:43 ) public JafSid getSid at java.lang.reflect.Method.invoke ( Method.java:498 ) { return sid; } ( at org . junit . runners . ) } {code} where JafSid is
{code:java} public class JafSid extends Base<BOJafSid> implements Sid { ( model . FrameworkMethod$1 . runReflectiveCall(FrameworkMethod . java:50 ) private Set<UserGroup> groups = new LinkedHashSet<> at org.junit.internal.runners.model.ReflectiveCallable.run ( ReflectiveCallable.java:12 ) ; ( at org . junit . runners . )
@IndexedEmbedded model.FrameworkMethod.invokeExplosively ( depth = 1, prefix = GROUPS + JSONFieldDefinition FrameworkMethod . MODEL_SUFFIX java:47 ) @ManyToMany at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively ( mappedBy = UserGroup ExtendedFrameworkMethod . MEMBERS java:45 ) @Cache at org.junit.internal.runners.statements.InvokeMethod.evaluate ( usage = CacheConcurrencyStrategy InvokeMethod . READ_WRITE java:17 ) public Set<UserGroup> getGroups at org.junit.internal.runners.statements.RunBefores.evaluate ( ) { return groups; } {code} where Base is {code:java} @Entity @Polymorphism(type = PolymorphismType RunBefores . EXPLICIT java:26 ) @Inheritance at org.junit.internal.runners.statements.RunAfters.evaluate ( strategy = InheritanceType RunAfters . JOINED java:27 ) @Cache at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call ( usage = CacheConcurrencyStrategy FailOnTimeout . READ_WRITE, include = "non-lazy" java:298 ) public abstract class Base<BO extends BOBase<? extends Base<BO>>> extends DatabaseEntity<BO> implements IBase { ( at org . junit . internal . runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292 ) } {code} where DatabaseEntity is {code: at java } @MappedSuperclass @BusinessLogic .util.concurrent.FutureTask.run ( relevantSecurityFields = {} FutureTask.java:266 ) public abstract class DatabaseEntity<BO extends BODatabaseEntity<? extends DatabaseEntity<BO>>> implements IDatabaseEntity, Comparable<DatabaseEntity<BO>> { ( at java . lang . Thread . run(Thread.java:748 ) } { code noformat } The issue This error happens in TwoPhaseLoad.doInitializeEntity, when the hydrated state of JafSid ExtendedSelfDirtinessTracker is applied during enhancement . getGroups Accessing size () is resolved.
!image-2018-03-22-16-47-49-937.png|thumbnail!
The collection that needs to be taken from this.xrefLoadingCollectionEntries throws the LazyInitializationException.
Maybe this already gives enough clues. As the inheritance structure of the entities is quite difficult, I wasn't able to prepare an isolated test case yet, but maybe this already helps to fix uninitialized collection triggers the issue exception . |
|