4 Replies Latest reply on Jul 26, 2010 5:18 AM by levis1984

    @ManyToMany: REVTYPE

    levis1984

      Hi,

       

      i have the two classes Person and Attribut, in short:

       

      @Entity
      @Indexed
      @Table(name="persons")
      public class Person {
       
        private int id;
        private List<Attribute> attributes;
       
       
        @Id
        @DocumentId
        @GeneratedValue
        @Column(name="person_id")
        public int getId() {
         return id;
        }
       
        @ManyToMany
        @JoinTable(
          name="attribute_alloc",
         
      joinColumns={@JoinColumn(name="person_id")},
         
      inverseJoinColumns={@JoinColumn(name="attribute_id")}
          )
        @Audited
        public List<Attribute> getAttributes() {
         return attributes;
        }
       
        // other properties, setters and getters...
      }


      @Entity
      @Indexed
      @Table(name="attributes")
      public class Attribute {
       
        private int id;
        private List<Person> persons;
       
       
        @Id
        @DocumentId
        @GeneratedValue
        @Column(name="attribute_id")
        public int getId() {
         return id;
        }
       
        @ManyToMany
        @JoinTable(
          name="attribute_alloc",
         
      joinColumns={@JoinColumn(name="attribute_id")},
         
      inverseJoinColumns={@JoinColumn(name="person_id")}
          )
        public List<Attribute> getPersons() {
         return persons;
        }
       
        // other properties, setters and getters...
      }


      For these classes the db tables persons, attributes, attribute_alloc, persons_aud, attributes_aud and attribute_alloc_aud were correctly generated.

       

      All works well except the audit for the attributes in Person. In the table attribute_alloc_aud the changes (for example removing an attribute and adding a new one to a person) are tracked correctly, but always marked with the REVTYPE ADD. For example:

       

       

      REVperson_idattribute_idREVTYPE
      1110
      1120
      2110
      2150
      3180

       

       

      Consequence is that the audited person in the last revision has the attributes 1, 2, 5 and 8. Correct would be only 8!

       

      What's wrong?

       

      Thanks a lot!

      Best regards

      Levi

        • 1. Re: @ManyToMany: REVTYPE
          adamw

          Shouldn't one mapping be inverse? That is, @ManyToMany(mappedBy = "").

           

          Adam

          • 2. Re: @ManyToMany: REVTYPE
            levis1984

            Hi Adam,

             

            thanks for your reply!

             

            I edited the annotation in the class Attribute:

              @ManyToMany(mappedBy="attributes")
              public List<Attribute> getPersons() {
               return persons;
              }

             

            But unfortunately it results in the same effect. REVTYPE is always ADD and consequently the audit entries are accumulated...

             

            Any other idea?

             

            Thanks so much!

            Levi

            • 3. Re: @ManyToMany: REVTYPE
              adamw

              Did you try with Hibernate 3.6 beta1 or with trunk?

              If so, could you maybe create a simple test case (there's quite a lot of test cases in Envers) and attach it to a JIRA bug? Then I could look at it

               

              Adam

              1 of 1 people found this helpful
              • 4. Re: @ManyToMany: REVTYPE
                levis1984

                Oh, I still used 3.5.0. I will try it with the new Version as soon as possible.

                I will report ;-)