Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-5995

DOCUMENT - HHH-2763: Unable to use bidiretional lazy relationship together with hibernate callback-listeners

XMLWordPrintable

    • Documentation (Ref Guide, User Guide, etc.)
    • Hide
      You are not allowed to initialize lazy collections or proxies during a flush. To workaround this issue, the listener should use a different session to initialize the collection. The following is an example of the workaround, which was added also into the Hibernate Entity Manager Reference Guide:

      SessionImplementor si = (SessionImplementor)(event.getSession());
      Session anotherSession = si.getFactory().openSession(si.getJDBCContext().connection());
      Object obj = anotherSession.get( event.getEntity().getClass(),event.getId());
      if(obj instanceof Parent){
      Parent parent = (Parent)obj;
      Iterator it = parent.getChildren().iterator();
      while(it.hasNext()){
      Child child = (Child)it.next();
      }
      }
      anotherSession.close()
      Show
      You are not allowed to initialize lazy collections or proxies during a flush. To workaround this issue, the listener should use a different session to initialize the collection. The following is an example of the workaround, which was added also into the Hibernate Entity Manager Reference Guide: SessionImplementor si = (SessionImplementor)(event.getSession()); Session anotherSession = si.getFactory().openSession(si.getJDBCContext().connection()); Object obj = anotherSession.get( event.getEntity().getClass(),event.getId()); if(obj instanceof Parent){ Parent parent = (Parent)obj; Iterator it = parent.getChildren().iterator(); while(it.hasNext()){ Child child = (Child)it.next(); } } anotherSession.close()
    • Documented as Resolved Issue

      When you use a hibernate event, if you try accessing a lazy collection, then the CollectionEntry corresponding to the lazily loaded collection get added to the PersistenceContext and hibernate crashes when it finds those entries because they are neither processed, neither ignored.

      The exception below is fired:
      Caused by: org.hibernate.AssertionFailure: collection [com.qualitype.testcase.server.ejb.entity.EntityB.entitiesOfA] was not processed by flush()
      at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)
      at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:333)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
      at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
      ... 29 more

      Please look for detailed comments about it at:
      http://opensource.atlassian.com/projects/hibernate/browse/HHH-2763

            ekopalov_jira Eva Kopalova (Inactive)
            rhn-support-alazarot Alessandro Lazarotti
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: