5 Replies Latest reply on Oct 11, 2012 4:04 AM by mdond

    envers writes audit entries despite transaction rollback

    mdond

      In the following scenario envers writes audit entries despite a transaction rollback (hibernate v3.6.5):

       

      In a single request we first start a write transaction where we manipulate an entity which is audited.

      The hibernate entity manager is flushed by our workflow engine and envers adds a workUnit to AuditProcess.

      After that and before the commit of the transaction an exception in the workflow engine occurs and the transaction is rolled back.

       

      With the rollback of the transaction the AuditProcess is removed from the AuditProcessManager:

       

      AuditProcessManager {

      ...

         public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {

            auditProcesses.remove(transaction);

         }

      }

       

      So far so good.

       

      However after this failed and rolled back transaction in the same request a new transaction is started and commited.

      This new transaction does not change any audited entity, however on commit of this new transaction the 'doBeforeTransactionCompletion'-Listener of the already removed AuditProcess is called:

       

      AuditProcess {

      ...

         public void doBeforeTransactionCompletion(SessionImplementor session) {

            ...

         }

      }

       

      and as this still contains the workUnit added in the first rolled back transaction, it now writes a new revision in the envers audit tables despite the change in the entity is already rolled back in the earlier transaction and so there hasn't been a change to audit at all.

       

      Is there anything we can do to avoid this?

       

      Best regards,

      Maarten Donders