Hibernate Envers With Existing Data

java.lang.RuntimeException: Cannot update previous revision for entity com.xxx.yyy.Users_audit 
and id 1
2015-11-12 16:22:19,168 ERROR [http-nio-8000-exec-3] EntitlementControllerAdvice: 
Unable to perform beforeTransactionCompletion callback
org.hibernate.AssertionFailure: Unable to perform beforeTransactionCompletion callback
...
...
...
Caused by: java.lang.RuntimeException: Cannot update previous revision for entity 
com.xxx.yyy.Users_audit and id 1
at org.hibernate.envers.strategy.ValidityAuditStrategy$1.doBeforeTransactionCompletion(ValidityAuditStrategy.java:223)

It’s because we configure ValidityAuditStrategy for audit strategy. Changing it to use DefaultAuditStrategy solve the problem, pheeeew…. (of course there are some trade off, which will not discuss here 🙂 )

From hibernate envers documentation:

ValidityAuditStrategy : Stores both the start revision and the end revision. Together these define when an audit row was valid.

DefaultAuditStrategy: Stores only the revision, at which an entity was modified.

 

 

dicksonkho

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.