Question

I am using envers to audit a User class and it saving all modified data in DB with rev number. Now, i need to recover all edited entities name, old value and new value by passing revision number as parameter.

I have read envers doc but could not find any solution for it.

Can anyone please suggest? thanks

Was it helpful?

Solution

A revision number uniquely identifies a version of an entity, hence when getting an entity at a specific revision, you get it with the values it had back then.

To get the old and new values of fields, if you know the entity has been changed at revision N, the easiest way is to get the entity at revisions N-1 and N and compare the fields you are interested in.

This can be done in a single query using the forRevisonsOfEntity query (see the AuditReader and AuditQueryCreator javadocs)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top