We have an application that tracks all the entity changes with bi-temporal data. Each entity has:
@Embeddable
public class AuditInfo {
private Date effectiveFrom;
private Date effectiveTo;
private Date asOf;
private Boolean isCurrent;
}
However on update of an entity we would like to insert a new record and update the old one with isCurrent = false and update the effectiveTo date with current date time.
Could I achieve this with Spring Jpa-Envers?
I tried wiring Hibernate Interceptors and later realised I can only modified the entity fields from within the interceptor and can’t do anything more than that.
I can easily add a service layer that will achieve this but it sounds a like it don’t belong in a service as it a cross cutting concern.
The other that we are toying with is a have custom repository and overriding the save() method.
Would appreciate your thoughts.