I have two audited entities joined by a ManyToMany relationship.When I look at the database after a persist I can see that there is a auditing table for each entity and an auditing table for the join table as expected. What I'm not clear on is the expected behavior when a change is made to the owning entity that does not involve the mapped entity. Currently, it is adding a revision to the auditing table for the join table every time even if the update has nothing to do with the mapped entity. Is this a bug or is it supposed to do that?
My code looks something like this:
//the owning entity @Entity(name = "Brand") @Table(name = "brands") @Audited public class Brand { @Id @DocumentId @GeneratedValue(strategy = GenerationType.AUTO) protected Long id; @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "brands_to_managers", inverseJoinColumns = { @JoinColumn(name = "person_id", referencedColumnName = "id") }, joinColumns = { @JoinColumn(name = "brand_id", referencedColumnName = "id") }) @AuditJoinTable(inverseJoinColumns = { @JoinColumn(name = "person_id", referencedColumnName = "id") }) public Set<Person> brandManagers; @Column public String name; } //the owned entity @Entity(name = "Person") @Table(name = "persons") @Audited @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Person { @Id @DocumentId @GeneratedValue(strategy = GenerationType.AUTO) protected Long id; @Column(nullable = true) public String username; }
Using the code above, if I were to make a change to Brand.name and persist it to the DB, in the brands_to_brand_managers_AUD table I would get a new revision with a REVTYPE of 0. I've also noticed that removing one of the owned entities from the realtionship does not result in a delete revision being added to the brands_to_brand_managers_AUD table. any help on this would be much appreciated.
That shouldn't happen for sure.
Would it be possible for you to create an Envers test case? (see the sources).
Adam