2 Replies Latest reply on Sep 16, 2010 5:18 AM by croqueteer

    Problem Auditing Elements in bi-directional relationships

    croqueteer

      Hi,

      I have a problem with auditing elements contained in a Set.

      http://docs.jboss.org/envers/docs/index.html#exceptions-onetomanyjoincolumn

      I do not use a join table.

       

      I am using Envers (3.5.5.Final) with JPA and Spring (3.0.3.RELEASE)

       

      These are my entities:

       

      @Entity

      @Table(name="OPERATOR")

      @Audited

      public class Operator {

      @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          @Column(name = "ID", nullable = false, updatable = false)
          private Integer id

       

      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)

      @JoinColumn(name = "OPERATOR_ID", nullable=false)

      @AuditMappedBy(mappedBy="operator")

      private Set<ConfigGroup> configGroups;

       

      Getters & Setters....

       

      }

       

      @Entity

      @Table(name="CONFIG_GROUP")

      @Audited

      public class ConfigGroup {

       

      @ManyToOne

      @JoinColumn(name="OPERATOR_ID", insertable=false, updatable=false, nullable=false)

      private Operator operator;

       

      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)

      @JoinColumn(name = "CONFIG_GROUP_ID",nullable=false)

      @AuditMappedBy(mappedBy="configGroup")

      private Set<Config> configs;

       

      Getters & Setters....

       

      }

       

       

      @Entity

      @Table(name = "CONFIG_VALUE")

      @Audited

      public class Config {

       

      @ManyToOne

      @JoinColumn(name="CONFIG_GROUP_ID", insertable=false, updatable=false, nullable=false)

      private ConfigGroup configGroup;

       

      Getters & Setters....

       

      }

       

      Now when I first persist my object graph i.e entityManager.persist(operator) everything is stored neatly and audited.

       

      If I then update my object graph by adding a few elements (i.e add a new ConfigGroup to Operator and the ConfigGroup contains a new Config) and then call entityManager.merge(operator). The new objects are properly stored by Hibernate, insert statements seems ok. But the new config element in the new ConfigGroup is never audited. The config group itself gets audited but not the contained Config. In the log I do not see an insert statement for the new Config object to its audit table.

       

      Earlier I had a problem where the ConfigGroup did not get audited even though an insert statement was logged.

      I managed to work around that one, but there also seems to be some issues with transactions... (I got insert statement and a new id was claimed/used from a db sequence)

       

      Any help would be greatly appreciated!

       

      Best regards,

      Henrik

        • 1. Re: Problem Auditing Elements in bi-directional relationships
          fbascheper

          This looks like a bug to me. Note that @AuditMapped by is still marked as experimental.

          You didn't per chance set org.hibernate.envers.revision_on_collection_change to false?

           

          Otherwise your best bet is try to create a test case against the envers trunk and create a Jira issue.

           

          Regards,

          Erik-Berndt

          • 2. Re: Problem Auditing Elements in bi-directional relationships
            croqueteer

            Thank you very much for your answer. Will try to create a test-case if I can find the time.

            And I am not using the org.hibernate.envers.revision_on_collection_change setting.

            Maybe I will try to implement this with a join table instead using @AuditJoinTable and I may even change the relationship to uni-directional so I can get something up and running in the near future.

             

            Thanks,

            Henrik