We are using Hibernate Envers to do our logging, but there was a requirement to set the type of event on the object which we are tracking the history. The property is required so we had the idea to put it to null
each time the lastEvent
wasn't set.
So we tried to set the property with @PrePersist
@PrePersist
public void checkIfLastEventWasModified() {
if (!lastEventModified) {
lastEvent = null;
}
}
But apparantly hibernate considers these interceptors to mark the object as dirty or not. So when this code was run on the dirty check, lastEventModified
is still false
and lastEvent
will be set to null
each time even if nothing changed on the object.
We also tried it with the EventListeners from Hibernate but they ran outside the transaction and we could set the property, but they weren't saved to the db.
Both solutions don't feel right, but I have no clue how we can solve this problem in the best way.