2 Replies Latest reply on Nov 5, 2012 6:21 AM by bdumas

    Audit record for an unchanged entity owner of a @ManyToMany relationship

    bdumas

      Hello,

       

      Sorry if this problem has already been reported (tThough it looks simple, I haven't been able to find a solution).

       

      I have two audited classes A and B with a ManyToMany relationship, which is also audited.

       

      @Audited

      class A {

       

        @ManyToMany

        @JoinTable(name = "A_B", joinColumns = { @JoinColumn(name = "ID_A") }, inverseJoinColumns = { @JoinColumn(name = "ID_B") })

         List<B>    bList;

      }

       

      @Audited

      class B {

       

        @ManyToMany

        @JoinTable(name = "A_B", joinColumns = { @JoinColumn(name = "ID_B") }, inverseJoinColumns = { @JoinColumn(name = "ID_A") })

        List<A>    aList;

      }

       

      In the database, I have tables A, B, A_B, A_AUD, B_AUD and A_B_AUD.

       

      When I modify an attribute in A, an audit record is inserted in A_AUD.

      When I modify an attribute in B, an audit record is inserted in B_AUD.

      When I add or remove an association from an A instance, an audit record is inserted in A_B_AUD but also in A_AUD.

       

      The modification is made like this :

      a.getBList().add(b);

      session.update(a);

       

      Is there a way to avoid the creation of an audit record in A_AUD when only the relation is modified (with keeping the audit record in A_B_AUD table) ?

       

      Thank you for your help.

       

      Benjamin