BTM
  1. BTM
  2. BTM-79

BitronixTransaction swallows any runtime exception thrown during beforeCompletion

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.3
    • Fix Version/s: 2.0.0
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Copy/pasting the initial report on the forum.

      My use case is pretty simple. I have a JPA PersonEntity with a
      uniqueId that I can set to whatever value. The uniqueId is associated
      to a unique constraint in the database. In one of my tests, I start a
      transaction and create the person with a uniqueID that already exists
      in the database. When the JPA/Hibernate transaction commits, I get
      this:

      org.hibernate.exception.ConstraintViolationException: Could not
      execute JDBC batch update
             at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
             at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
             at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
             at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
             at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
             at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
             at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
             at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
             at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
             at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)
             at bitronix.tm.BitronixTransaction.fireBeforeCompletionEvent(BitronixTransaction.java:429)
             at bitronix.tm.BitronixTransaction.commit(BitronixTransaction.java:173)
             at bitronix.tm.BitronixTransactionManager.commit(BitronixTransactionManager.java:103)
             at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1028)
      

      What I am expecting is to get this exception in the caller and have
      the transaction rolledback. What I get instead is this

      org.springframework.transaction.UnexpectedRollbackException: JTA
      transaction unexpectedly rolled back (maybe due to a timeout); nested
      exception is bitronix.tm.internal.BitronixRollbackException:
      transaction was marked as rollback only and has been rolled back
             at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1031)
      

      It seems that the problem lies in the code or I misconfigured BTM

      In BitronixTransaction, there is this piece of code

              try {
                     if (log.isDebugEnabled()) log.debug("executing
      synchronization " + synchronization);
                     synchronization.beforeCompletion();
                 } catch (RuntimeException ex) {
                     log.warn("Synchronization.beforeCompletion() call
      failed for " + synchronization + ", marking transaction as rollback
      only", ex);
                     setStatus(Status.STATUS_MARKED_ROLLBACK);
                     return;
                 }
      

      The problem with this is that my runtime exception is caught, the
      transaction is marked as rollbacked which is good from a transactional
      standpoint but I don't get the error at all. What happens next is that
      Spring finalize the commit of the transaction (since no exception was
      raised) and realize that it has been set to rollbackOnly meanwhile,
      leading to this exception.

        Issue Links

          Activity

          Hide
          Stéphane Nicoll added a comment -

          Actually the affect is 2.0.0-beta1. I haven't tried with 1.3.3

          Show
          Stéphane Nicoll added a comment - Actually the affect is 2.0.0-beta1. I haven't tried with 1.3.3
          Hide
          Ludovic Orban added a comment -

          fixed in trunk.

          Show
          Ludovic Orban added a comment - fixed in trunk.
          Hide
          Stéphane Nicoll added a comment -

          Thanks Ludovic. I have rebuilt BTM from trunk and re-run my scenario which works now as I expected. I have also ran our full test suite over here and found no regression.

          When can you deploy a beta2 on the maven repo?

          Show
          Stéphane Nicoll added a comment - Thanks Ludovic. I have rebuilt BTM from trunk and re-run my scenario which works now as I expected. I have also ran our full test suite over here and found no regression. When can you deploy a beta2 on the maven repo?

            People

            • Assignee:
              Ludovic Orban
              Reporter:
              Stéphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: