Marcel -
On CriteriaDelete: delete from TABLE where CONDITIONS
One could do (before the delete executes): insert into TABLE_AUDIT select AUDIT_COLOMS from TABLE where CONDITIONS
For a simple entity that doesn't have any associations that are not marked to be cascade deleted, this might suffice. The problem is we need to be able to support not only the simplest of cases, but also far more complex situations too. Here's a mapping that isn't as trivial that involves needing to track not only the deletions against EntityA when a bulk delete operation occurs, but also those made against EntityB.
@Audited
@Entity(name = "EntityA")
public static class EntityA {
@Id
private Integer id;
private String name;
@OneToOne(mappedBy = "a", cascade = CascadeType.ALL)
private EntityB b;
}
@Audited
@Entity(name = "EntityB")
public static class EntityB {
@Id
private Integer id;
@OneToOne
@OnDelete(action = OnDeleteAction.CASCADE)
private EntityA a;
}
We can certainly take some time to look at this in the future, but meanwhile users can either elect to use database features or iterate objects as needed to get the proper Hibernate ORM events to be raised so that Envers performs the audit operations needed. |