spring-boothibernate-envers

Capture result of Envers update action


Please help me that how can I determine the result of Envers update for below scenario:

Currently I am receiving data in request object from front end. I fetch data from db against provided request object ID then mapping request object values to object fetched from db and saving it (in short update request). On saving, there is no entry in db audit table if no field changed. Now I want to determine that if Envers adding any row in audit table or not in case action is update as I want to take some action based on this behavior. For instance below is my code:

Student savedStudent= repository.save(student);
createQueueEvent("update", savedStudent);

if Envers logged row after repository.save(student) call then I want to call method createQueueEvent

Note: I do not want to perform equal checks for objects


Solution

  • I resolved this issue by creating a class which implements RevisionListener and overriding method newRevision of RevisionListener. This method will only be invoked when there is any update/insert/delete in audit table else this method will not get triggered.
    I am initializing a thread in new class like this:

    public static final ThreadLocal<Boolean> isAudit= new ThreadLocal<>();   
    

    and setting boolean value to true in newRevision method.
    Then in my service class after repository.save(student) call, I check if value is true then calling createQueueEvent method else nothing