We use Hibernate 5.6. We have two entities: A and B, B is OneToMany mapped to A as a value of a map; and four tables used for the child and auditing.
@Entity
@Audited
public class A {
private String id;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "a_id"), inverseJoinColumns = @JoinColumn(name = "b_id"))
@MapKeyColumn(name = "propertyName", nullable = false)
@AuditJoinTable(name = "A_B_ADT")
private Map<String, B> bEntities = new HashMap<>();
}
@Entity
@Audited
public class B {
private String id;
private String propertyName;
}
Table A_B (a_id, b_id, propertyName);
Table A_B_ADT (REV, REVTYPE, a_id, b_id, propertyName);
Table B (id, propertyName, propertyValue);
Table B_ADT (id, REV, REVTYPE, propertyName, propertyValue)
When we add a child, or update an existing child' propertyValue, every thing is fine, audit data is insert into the B_ADT table with new REV.
But when we try to delete an existing child, the child is deleted from B table and also deleted from B_ADT table. But the A_B_ADT table got insert a new record about the deletion.
We need to keep the deleted child audit data in B_ADT table.