1 Reply Latest reply on Oct 3, 2012 7:31 PM by mrapczynski

    Does Envers work with merge?

    mrapczynski

      Hello,

       

      I just discovered and implemented Envers fresh into my project today. It's great, and an awesome time saver for my project. I am using Grails 2.1 with the Hibernate 3.6.10 package. I am using a custom defined RevisionEntity specifically to grab the logged in user from SpringSecurity. My project uses Spring Webflows to model a "create" workflow, and an "edit" workflow for leave requests. If I follow the create workflow end-to-end, Envers works great and logs the changes.

       

      However for the edit workflow I have to handle Hibernate persistence a little bit differently. Because using entities in a webflow invariably results in the entity becoming dettached from the Hibernate session, I need to save changes to existing entities using merge. I have noticed that changes applied and persisted through the database are not tracked with Envers when I use merge. Is this a correct understanding? Or am I missing something that I need to in order to get merge to trigger audit events.

       

      Thanks,

       

      Matt

       

      P.S. - I set up an instance of EntityTrackingRevisionListener, and attached logging handlers to both entityChanged(...) and newRevision(...) - neither of these are triggered when merging an object

        • 1. Re: Does Envers work with merge?
          mrapczynski

          Okay scratch all of that.

           

          I extended AuditEventListener to figure out what exactly is going on in the audit event lifecycle, and I noticed that PostUpdate events were in fact being fired. The problem was Grails allows for a combination merge and flush in one method call. I needed to reverse that practice, call merge with the flush flag specifically set to false, and then call save(...) once at the end of the workflow. Only then will the changes and the audit be serialized together.

           

          With that solved, Envers is great!