]
Roman Pichlík commented on HHH-2756:
------------------------------------
Collection has to be mapped with fetch="join" strategy.
PostLoadEventListener is triggered on not fully loaded entity
-------------------------------------------------------------
Key: HHH-2756
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2756
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.4.sp1
Reporter: Roman Pichlík
Priority: Minor
PostLoadEventListener is triggered, but entity is not fully loaded especially is not
possible to operate on mapped collection because
org.hibernate.LazyInitializationException: illegal access to loading collection is thrown.
PostLoadEventListener should be triggered when is entity fully loaded.
Let say, we have Parent, Child entity and PostLoadEventListener which iterates over child
collection.
public class Parent {
private Set<Child> children;
}
public class PostLoadEventListener implements PostLoadEventListener {
public void onPostLoad(PostLoadEvent event) {
Parent parent = (Parent) event.getEntity();
for(Child child: parent.getChildren()){ //
org.hibernate.LazyInitializationException: illegal access to loading collection
System.out.println(child);
}
}
}
Fix tip: see org.hibernate.loader.Loader#initializeEntitiesAndCollections, if i
understood well the key are following statements.
if ( hydratedObjects!=null ) {
int hydratedObjectsSize = hydratedObjects.size();
if ( log.isTraceEnabled() ) {
log.trace( "total objects hydrated: " + hydratedObjectsSize );
}
for ( int i = 0; i < hydratedObjectsSize; i++ ) {
TwoPhaseLoad.initializeEntity( hydratedObjects.get(i), readOnly, session, pre, post
); //event is trigerred here
}
}
//but collection are loaded by this code
if ( collectionPersisters != null ) {
for ( int i=0; i<collectionPersisters.length; i++ ) {
if ( !collectionPersisters[i].isArray() ) {
endCollectionLoad( resultSetId, session, collectionPersisters[i] );
}
}
}
//post event handlers should be trigerred here
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: