0 Replies Latest reply on May 23, 2005 5:13 PM by Denis Souza

    Problem with ManyToMany, fetchType=Lazy

    Denis Souza Newbie

      I've been strugling with a problem the past few days that I started getting in a many-to-many relationship. I found a way around it, but it might be a bug in hibernante/ejb3.

      I have a "Category" class with two many-to-many relationships to itself: "parents" and "children". I had set them to fetchType=LAZY and it just stopped working after a few days giving me an exception whenever I tried to fetch an instance of "Category":

      javax.transaction.TransactionRolledbackException
      Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=brain/83, BranchQual=, localId=83] status=STATUS_NO_TRANSACTION; - nested throwable: (java.util.ConcurrentModificationException)
      


      This only started happening after I had three levels of nesting in the parents/children relationship. (eg. OBJ1 --child--> OBJ2 --child--> OJB3)
      Removing the third level gets everything working again.

      Looking at JBOSS' log file something caught my eye:

      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.TwoPhaseLoad] resolving associations for [product.grouping.ProductCategory#10]
      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.CollectionLoadContext] creating collection wrapper:[product.grouping.ProductCategory.parents#10]
      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.CollectionLoadContext] creating collection wrapper:[product.grouping.ProductCategory.children#10]
      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.TwoPhaseLoad] done materializing entity [product.grouping.ProductCategory#10]
      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.CollectionLoadContext] 0 collections were found in result set
      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.CollectionLoadContext] 0 collections initialized
      2005-05-23 17:39:56,468 DEBUG [org.hibernate.engine.PersistenceContext] initializing non-lazy collections
      


      Note the last line being "initializing non-lazy collections". I though it might just be a typo but then I tried changing the relationship from LAZY to EAGER and it started to work fine.

      I thought this might be some kind of bug in the lazy-loading.

      thoughts?

      Denis Souza