In my audited entity I have last modified 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 don't understand how to implement this, because I always get the following error:
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?
@PreRemove
is to alter that current entity-state in memory prior to the event listeners for auditing. That said, Envers does not store non-primary key attributes by default for deleted rows. There is a configuration option,org.hibernate.envers.store_data_at_delete
which needs to be set to true to accomplish this. – Gascony