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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: EAP_EWP 5.1.0
    • Fix Version/s: TBD EAP 5
    • Component/s: Hibernate
    • Labels:
      None
    • Environment:

      Fedora 12, jdk1.6, MySQL 5.1 InnoDB

    • Release Notes Text:
      Hide
      You are not allowed to initialize lazy collections or proxies during a flush. The workaround is for the listener to use a different session to initialize the collection. The following is an example of the workaround:

      <programlisting language="Java" role="JAVA">
      SessionImplementor si = (SessionImplementor)(event.getSession());
      Session anotherSession = si.getFactory().openSession(si.getJDBCContext().connection());
      Object obj = anotherSession.get( event.getEntity().getClass(),event.getId());
      if(o instanceof Parent){
      Parent parent = (Parent)obj;
      Iterator it = parent.getChildren().iterator();
      while(it.hasNext()){
      Child child = (Child)it.next();
      }
      }
      anotherSession.close()
      </programlisting>
      Show
      You are not allowed to initialize lazy collections or proxies during a flush. The workaround is for the listener to use a different session to initialize the collection. The following is an example of the workaround: <programlisting language="Java" role="JAVA"> SessionImplementor si = (SessionImplementor)(event.getSession()); Session anotherSession = si.getFactory().openSession(si.getJDBCContext().connection()); Object obj = anotherSession.get( event.getEntity().getClass(),event.getId()); if(o instanceof Parent){ Parent parent = (Parent)obj; Iterator it = parent.getChildren().iterator(); while(it.hasNext()){ Child child = (Child)it.next(); } } anotherSession.close() </programlisting>
    • Release Notes Docs Status:
      Documented as Known Issue

      Description

      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

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  stliu Strong Liu
                  Reporter:
                  alessandrolt Alessandro Lazarotti
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: