[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6043) PostLoad method invoked before collection initialised

Arjan Tijms (JIRA) noreply at atlassian.com
Sun Aug 7 15:49:04 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43186#comment-43186 ] 

Arjan Tijms commented on HHH-6043:
----------------------------------

Things that should be simple are made very complicated now without this being fixed.

> PostLoad method invoked before collection initialised
> -----------------------------------------------------
>
>                 Key: HHH-6043
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6043
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: entity-manager
>    Affects Versions: 3.6.2
>         Environment: Windows 7 64-bit, hibernate 3.6.2 final, sun java 1.6 64 bit
>            Reporter: Setanta Mathews
>         Attachments: bugTestCase.rar
>
>
> Hi,
> I had been monitoring this bug under Jboss's https://issues.jboss.org/browse/JBAS-5474 . However the issue was recently closed.
> The description for that bug was 
> {quote}
> I have a bean with a @OneToMany relation mapping like
> private List<TherapieeinheitBean> therapieeinheiten;
> @OneToMany(
> cascade = {CascadeType.REFRESH},
> fetch = FetchType.EAGER,
> mappedBy="therapiekatalog"
> )
> with FetchType.EAGER and a simnple @PostLoad like
> @PostLoad
> public void postLoad() { System.out.println("!!!!!!!!!! postLoad !!!!!!!!!!"); System.out.print("size: " + therapieeinheiten.size()); }
> When an entity of this bean is loaded JBoss trows
> org.hibernate.LazyInitializationException: illegal access to loading collection
> at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
> at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
> at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249)
> at de.visiodesk.therapiekatalog.TherapiekatalogBean.postLoad(TherapiekatalogBean.java:170)
> .
> .
> .
> and prints the messages
> WARN [LoadContexts] fail-safe cleanup (collections) : org.hibernate.engine.loading.CollectionLoadContext at 2c8ce9<rs=Ingres-ResultSet[18523]>
> WARN [CollectionLoadContext] On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [206] entries
> afterwards. The PostLoad method should be called after the data was completely loaded. Is there a workaround for this Problem? I found some other ressources on the net where peole had the same problem, but I saw no resolution, no hint, no workaround.
> {quote}
> I can confirm that this issue still exists for the Hibernate 3.6.2 release. 
> The attached bugTestCase.rar contains a modified version of the test that was originally attached to the JBoss bug. I've changed it to work with spring and JPA. 
> Note that the attached test passes as the test is annotated with @Test(expected=PersistenceException.class)
> The stack trace from the exception thrown is
> {code}
> javax.persistence.PersistenceException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:635)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:589)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
> 	at $Proxy18.find(Unknown Source)
> 	at org.hibernate.bugs.lazyinitexception.LazyInitBug.testAccessAssociatedSetInPostLoad(LazyInitBug.java:48)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> 	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
> 	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
> 	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
> 	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> 	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
> 	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> 	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
> 	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
> 	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
> 	at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
> 	at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162)
> 	at org.hibernate.bugs.lazyinitexception.Parent.postLoad(Parent.java:42)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:37)
> 	at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:94)
> 	at org.hibernate.ejb.event.EntityCallbackHandler.postLoad(EntityCallbackHandler.java:87)
> 	at org.hibernate.ejb.event.EJB3PostLoadEventListener.onPostLoad(EJB3PostLoadEventListener.java:47)
> 	at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:250)
> 	at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
> 	at org.hibernate.loader.Loader.doQuery(Loader.java:857)
> 	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
> 	at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
> 	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
> 	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
> 	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
> 	at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
> 	at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
> 	at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
> 	at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
> 	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
> 	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
> 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
> 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:614)
> 	... 36 more
> {code}
> A copy of the

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list