1 Reply Latest reply on May 12, 2010 2:22 AM by Adam Warski

    Problem with Bidirectional ManyToMany to Self

    John Gilbert Apprentice
      I am having trouble with this many to many association to itself.

       

      {code}

      @Entity
      @Audited
      public class PricingElement {

       

          ...
         
          @ManyToMany(fetch = FetchType.LAZY)
          public Set<PricingElement> getOverrides() {...}

       

       

          @ManyToMany(fetch = FetchType.LAZY, mappedBy = "overrides")
          public Set<PricingElement> getOverriddenBy() {...}
         
          ...
      }

      {code}

       

      The audit records are inserted properly, but I get this exception when I query for the revisions and de-reference the collections.

       

      The interesting/weird thing is that if I flip the owning side (i.e. move the mappedBy attribute to the other getter) then it works.

       

      Any ideas on what is wrong? I've been debugging this all day but there is no obvious cause...

      Also, I have other ManyToMany associations (not to self) that work fine.

       

      I am using version: 1.2.2.GA-hibernate-3.3

       

      {code}

      org.hibernate.QueryException: could not resolve property:  originalId.overriddenBy_id of: PricingElement_PricingElement_AUD [

      select new list(ee, e)
      from PricingElement_PricingElement_AUD ee,  net.taylor.catalog.domain.pricing.PricingElement_AUD e
      where ee.originalId.PricingElement_id = e.originalId.id and  ee.originalId.overriddenBy_id = :overriddenBy_id and e.originalId.REV.id = (

      select max(e2.originalId.REV.id
      from net.taylor.catalog.domain.pricing.PricingElement_AUD e2
      where e2.originalId.REV.id <= :revision and e.originalId.id = e2.originalId.id

      ) and ee.originalId.REV.id = (

      select max(ee2.originalId.REV.id
      from PricingElement_PricingElement_AUD ee2
      where ee2.originalId.REV.id <= :revision and  ee.originalId.overriddenBy_id = ee2.originalId.overriddenBy_id and  ee.originalId.PricingElement_id = ee2.originalId.PricingElement_id

      ) and ee.REVTYPE != :delrevisiontype and e.REVTYPE != :delrevisiontype
      ]
           at  org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)
           at  org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:82)
           at  org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
           at  org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1377)
           at  org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:338)
           at  org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:313)
           at  org.hibernate.hql.ast.tree.FromElement.toColumns(FromElement.java:411)
           at  org.hibernate.hql.ast.tree.DotNode.getColumns(DotNode.java:134)
           at  org.hibernate.hql.ast.tree.DotNode.initText(DotNode.java:253)
           at  org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:228)
           at  org.hibernate.hql.ast.tree.DotNode.resolveFirstChild(DotNode.java:176)
           at  org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:482)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4326)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1212)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1690)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
           at  org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
           at  org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251)
           at  org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
           at  org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
           at  org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
           at  org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
           at  org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
           at  org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
           at  org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
           at  org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
           at  org.hibernate.search.impl.FullTextSessionImpl.createQuery(FullTextSessionImpl.java:313)
           at  org.jboss.seam.persistence.HibernateSessionProxy.createQuery(HibernateSessionProxy.java:141)
           at  org.hibernate.search.impl.FullTextSessionImpl.createQuery(FullTextSessionImpl.java:313)
           at  org.jboss.seam.persistence.HibernateSessionProxy.createQuery(HibernateSessionProxy.java:141)
           at  org.hibernate.envers.entities.mapper.relation.query.TwoEntityQueryGenerator.getQuery(TwoEntityQueryGenerator.java:110)
           at  org.hibernate.envers.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:62)
           at  org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50)
           at  org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.iterator(CollectionProxy.java:70)
           at  net.taylor.audit.envers.ChangeHistory.handleCollection(ChangeHistory.java:203)
           at  net.taylor.audit.envers.ChangeHistory.diff(ChangeHistory.java:151)
           at  net.taylor.audit.envers.ChangeHistory.getRevisions(ChangeHistory.java:123)
           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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at  org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
           at  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at  org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at  org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at  org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at  org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at  org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at  org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at  net.taylor.audit.envers.ChangeHistory_$$_javassist_seam_9.getRevisions(ChangeHistory_$$_javassist_seam_9.java)

      {code}