Hibernate Envers not calling pre-persist method on original object when storing corresponding audit entity

Viewed 120

I have an entity class which modifies one of its fields before storing it in the DB using @PrePersist. It then reverses this change in the entity after persisting using @PostLoad, @PostUpdate, @PostPersist (so the code never sees the modification).

@Audited
public class MyClass {

@PrePersist
public void someMethod() {
   ...some code which modifies a field value before persisting
}

@PostLoad
@PostUpdate
@PostPersist
public void reverseMethod() {
   ...some code which reverses the modification to the field value
}
    

This works fine normally but when Envers stores the corresponding Audit entity these methods on MyClass are not called meaning that the Audit is stored without the appropriate modification to this field (since the original entity immediately reverses the change after persisting and just before the corresponding audit is inserted).

When using Hibernate Envers do we have to call these annotated methods explicitly if we want them to be executed while the audit entry is being inserted?

0 Answers
Related