1 Reply Latest reply on Mar 1, 2013 2:36 PM by adamw

    Envers call to Session.flush() after transaction has been marked rollback only can mask original exception

    eugene75

      In Hibernate 4.1.7 using managed flush mode (in this case with JBoss AS7 and JPA),  if errors occur in the second flush(), those errors mask the error original generated by the event listener.

       

      For example, a transaction in which two entities are deleted.  A custom event listener allows the first but throws an exception on the second.  This causes the action queue to not be cleared (ActionQueue.executeActions(List)).  Envers then calls Session.flush() again in AuditProcess.doBeforeTransactionCompletion().  The attempt to execute the first entity delete a second time results in an "org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)".

       

      Throwing an exception from an event listener causes the transaction to be marked rollback only.  Think Envers should check is transaction is marked rollback only and take no action if it is.

       

      Workaround is to explicitly clear the action queue in the event listener before throwing the exception. (event.getSession().getActionQueue().clear())