4 Replies Latest reply on Oct 1, 2012 8:51 AM by rlu

    Problems loading ManyToMany Relations

    rlu Newbie

      I have to Entities A and B with many

       

      {code}

      @Entity

      @Audited

      public class A {

           ...

           @ManyToMany(fetch = FetchType.EAGER)

           private Set<B> b;

      }

       

      @Entity

      @Audited

      public class B {

      ...

      }

      {code}

       

      Changes in relationship are written in audit table (A_B_AUD), trying to read an old revision of A AuditReader method forEntitiesAtRevisions returns an empty set for b.

      While using following code resultset contains one element of B, but in database are 2 elements

       

      {code}

      public class AuditLogReader {

          

           public <T> AuditedEntity<T> getAuditVersion(Class<T> type, long id, int revision) {       

                  AuditReader reader = getAuditReader();

                 

      Object[] revisionData = (Object[]) reader.createQuery()

                          .forRevisionsOfEntity(type, false, false)

                          .add(AuditEntity.id().eq(id))

                          .addOrder(AuditEntity.revisionProperty("id").desc())

                          .setMaxResults(1)

                          .getSingleResult();

                  return new AuditedEntity<T>((T)revisionData[0], (RevisionEntity) revisionData[1]);

           }

      }

      {code}

       

      The application is ejb3 deployed in jboss 7.1.1.FINAL (containing envers module 4.0.1-FINAL)

      maybe i miss something.