1 Reply Latest reply on Aug 31, 2010 4:38 PM by bchicos

    Dealing with OptimisticLockExceptions using global SEAM transactions



      I have an application that may encounter OptimisticLockException's if 2 users update the same record at the same time. I would like for the application to be able to handle this gracefully... Therefore I would like to be able to add some exception handling code that refreshes the current record when an update fails. I am not able to do that however because since the transaction has failed.. I can no longer use it and I get the following error.
      
      2010-08-31 13:52:56,373 DEBUG [org.hibernate.util.JDBCExceptionReporter.logExceptions] Cannot open connection [???]
      org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a4b1921:e92:4c7d40e8:26d status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a4b1921:e92:4c7d40e8:26d status: ActionStatus.ABORT_ONLY >)
      
      I would like to know what the best practice for this is. It seems like a common scenario. In standard EJB I would typically call a method to recover from this with the requires_new annotation.
      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      This does not seem to be available using SEAM transactions however.
      
      We are injecting the entityManager via @In.
      
      @In
      private EntityManager entityManager;
      
      In components.xml we are configured to use a managed-persistence-context.
      
      
              <persistence:managed-persistence-context name="entityManager" 
                                        auto-create="true"
                         persistence-unit-jndi-name="java:/EntityManagerFactories/entityManager"/>
      
      

      
      



        • 1. Re: Dealing with OptimisticLockExceptions using global SEAM transactions

          Updated the formatting of my question. 


          I have an application that may encounter OptimisticLockException's if 2 users update the same record at the same time. I would like for the application to be able to handle this gracefully... Therefore I would like to be able to add some exception handling code that refreshes the current record when an update fails. I am not able to do that however because since the transaction has failed.. I can no longer use it and I get the following error.




          010-08-31 13:52:56,373 DEBUG [org.hibernate.util.JDBCExceptionReporter.logExceptions] Cannot open connection [???]
          org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a4b1921:e92:4c7d40e8:26d status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a4b1921:e92:4c7d40e8:26d status: ActionStatus.ABORT_ONLY >)





          I would like to know what the best practice for this is. It seems like a common scenario. In standard EJB I would typically call a method to recover from this with the requiresnew annotation.
          @TransactionAttribute(TransactionAttributeType.REQUIRES
          NEW)
          This does not seem to be available using SEAM transactions however.


          We are injecting the entityManager via @In.


          @In
          private EntityManager entityManager;


          In components.xml we are configured to use a managed-persistence-context.




              <persistence:managed-persistence-context name="entityManager" 
                                            auto-create="true"
                             persistence-unit-jndi-name="java:/EntityManagerFactories/entityManager"/>