In my audited entity i have fields:
@LastModifiedBy
private String lastModifiedBy;
@LastModifiedDate
private OffsetDateTime lastModifiedDate;
But they doesn’t change when entity is deleted.
As i understand, i need to customize org.springframework.data.jpa.domain.support.AuditingEntityListener
and add @PreRemove
there, but i dont understand how to implement this, because i’m always have
org.hibernate.InstantiationException: Could not instantiate managed bean directly
Is there any other options to track delete events and store updated fields to Envers audit table ?
made this workaround:
public class CustomValidityAuditStrategy extends ValidityAuditStrategy {
private final AuditorAware<String> auditorAware = ...;
@Override
public void perform(final Session session, final String entityName, final AuditEntitiesConfiguration audEntitiesCfg, final Serializable id, final Object data, final Object revision) {
if (data instanceof Map) {
final Map dataToUpdate = (Map) data;
dataToUpdate.put("lastModifiedBy", auditorAware.get());
dataToUpdate.put("lastModifiedDate", OffsetDateTime.now());
}
super.perform(session, entityName, audEntitiesCfg, id, data, revision);
}
}