5 Replies Latest reply on Oct 6, 2008 1:30 PM by xshuang

    @PostLoad invoked before eagerly loaded property finishes lo

    jluv

      I have an entity which has a Map set to load eagerly. When trying to access the map in a method annotated as PostLoad, I am getting a LazyInitializationException ("illegal access to loading collection") from AbstractPersistentCollection.java:341

      /**
       * Initialize the collection, if possible, wrapping any exceptions
       * in a runtime exception
       * @param writing currently obsolete
       * @throws LazyInitializationException if we cannot initialize
       */
       protected final void initialize(boolean writing) {
       if (!initialized) {
       if (initializing) {
       throw new LazyInitializationException("illegal access to loading collection");
       }
       throwLazyInitializationExceptionIfNotConnected();
       session.initializeCollection(this, writing);
       }
       }
      


      Correct me if I am wrong, but I think a PostLoad method should not be fired until eagerly loaded properties are finished.

      In other words, listeners.onPostLoad(postLoadEvent) from TwoPhaseLoad.initializeEntity shouldn't be invoked until the "initializing" field in each of the entity's eagerly loaded AbstractPersistentCollection objects is set to false.

      Any thoughts on whether this should be considered a bug?

      How about any ideas for a workaround?


        • 1. Re: @PostLoad invoked before eagerly loaded property finishe
          icordoba

          Hi;
          I am having the same problem in a Entity postLoad method which access a eagerly loaded Set. Wierd as it doesn't happen on every Load of the entity... :-/

          Did you find any sollution on this?

          thanks,
          Ignacio

          • 2. Re: @PostLoad invoked before eagerly loaded property finishe
            icordoba

            My Exception:

            Caused by: javax.persistence.PersistenceException: org.hibernate.LazyInitializationException: illegal access to loading collection
             at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
             at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:194)
             at org.jboss.ejb3.entity.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:171)
             at com.servengine.user.UserManagerBean.getUser(UserManagerBean.java:839)
             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:585)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
             at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
             at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
             ... 60 more
            Caused by: 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.PersistentSet.iterator(PersistentSet.java:163)
             at com.servengine.user.User.ejbLoad(User.java:119)
             at sun.reflect.GeneratedMethodAccessor1187.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:23)
             at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:78)
             at org.hibernate.ejb.event.EntityCallbackHandler.postLoad(EntityCallbackHandler.java:71)
             at org.hibernate.ejb.event.EJB3PostLoadEventListener.onPostLoad(EJB3PostLoadEventListener.java:35)
             at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:201)
             at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
             at org.hibernate.loader.Loader.doQuery(Loader.java:729)
             at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
             at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
             at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
             at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
             at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
             at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
             at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
             at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
             at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
             at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
             at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
             at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
             at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
             at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
             ... 75 more
            


            • 3. Re: @PostLoad invoked before eagerly loaded property finishe
              deanouk

              Did either of your find a solution to this? Still having the same problem.

              • 4. Re: @PostLoad invoked before eagerly loaded property finishe
                kindkid

                I'm having the same problem. :/

                I see that this issue is also mentioned here:
                http://forum.hibernate.org/viewtopic.php?p=2380528

                • 5. Re: @PostLoad invoked before eagerly loaded property finishe
                  xshuang

                  Anyone find a solution? Thanks a lot.