2 Replies Latest reply on Apr 1, 2013 4:17 PM by calowensnay

    auditing many to many relationship with extra columns

    calowensnay Newbie

      Hi,

      I've created a ManyToMany relationship with extra columns and it works fine. But when I try to add Envers, the following error appears. I'm using Hibernate + Envers 3.6.10

       

      {code:java}Initial SessionFactory creation failed: could not init listeners

      org.hibernate.HibernateException: could not init listeners

           at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)

           at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:2010)

      ....

       

      Caused by: org.hibernate.MappingException: Type not supported: org.hibernate.type.ManyToOneType

          at org.hibernate.envers.configuration.metadata.IdMetadataGenerator.addIdProperties(IdMetadataGenerator.java:75)

          at org.hibernate.envers.configuration.metadata.IdMetadataGenerator.addId(IdMetadataGenerator.java:120)

          at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:412)

          at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:102)

          at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:97)

          at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:129){code}

      .....

       

       

      But When I use ibernate 4.1.0  the error is:

       

      {code}

      Initial SessionFactory creation failed: Unable to read the mapped by attribute for listAB in com.arplatia.ns.server.prueba.AB!

      org.hibernate.MappingException: Unable to read the mapped by attribute for listAB in com.arplatia.ns.server.prueba.AB!

          at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.getMappedBy(CollectionMetadataGenerator.java:589)

          at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.addOneToManyAttached(CollectionMetadataGenerator.java:179)

          at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.addCollection(CollectionMetadataGenerator.java:161)

          at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addValueInSecondPass(AuditMetadataGenerator.java:223)

          at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addValue(AuditMetadataGenerator.java:245)

          at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addProperties(AuditMetadataGenerator.java:258)

      ....{code}

       

      Here are the classes with the annotations:

       

      Class A

       

      {code}@Entity

      @Audited

      public class A implements Serializable {

       

         //Sttributes

         //Construnctor methods

         //Getters and Setters

       

          @Id

          @GeneratedValue

          public Long getId() {

              return id;

          }


          @OneToMany (mappedBy = "id.a")

          @Cascade(CascadeType.ALL)

          @LazyCollection(LazyCollectionOption.TRUE)

          public Set<AB> getListAB() {

              return listAB;

          }

       

         //Hashcode and Equals

       

       

      {code}

       

       

      Class B

       

      {code}@Entity

      @Audited

      public class B implements Serializable{

       

        //Attributes

        //Constructor methods

      // Getters and Setters

       

          @Id

          @GeneratedValue

          public Long getId() {

              return id;

          }

       

          @OneToMany (mappedBy = "id.b")

          @LazyCollection(LazyCollectionOption.TRUE)

          public Set<AB> getListAB() {

              return listAB;

          }

       

        //HashCode and Equals

       

      }{code}

       

       

      Class AB

       

      {code}@Entity

      @Audited

      @AssociationOverrides({

          @AssociationOverride(name = "id.a",

              joinColumns = @JoinColumn(name = "a_id")),

          @AssociationOverride(name = "id.b",

              joinColumns = @JoinColumn(name = "b_id")) })

      public class AB implements Serializable {

       

            //Attributes

           //Constructor Methods

           //Getters and Setters


          @EmbeddedId

          public ABId getId() {

              return id;

          }

       

          @Transient

          public A getA() {

              return getId().getA();

          }

       

          @Transient

          public B getB() {

              return getId().getB();

          }

       

           //HashCode and Equals

       

      }{code}

       

      Class ABId

       

      {code}@Embeddable

      public class ABId implements Serializable {

       

       

           //Attributes

           //Constructor Methods

           //Getters and Setters

       

          @ManyToOne

          public A getA() {

              return a;

       

          }

       

          @ManyToOne

          public B getB() {

              return b;

          }

       

         //HashCode and Equals

         }{code}

       

       

      Can someone tell me what'is wrong with this code?