2 Replies Latest reply on Oct 2, 2006 5:11 AM by marook

    Transactions Rollback

    marook

      Hello Experts,

      I've got a problem with the rollback of failed transactions. My situation is as follows:

      @Stateless
      @Local
      public class BeanA implements IBeanA{
      
       @PersistenceContext(name="MyContext")
       private EntityManager entityManager;
      
       public void persistSomething() {
       entityManager.persist(new MyEntityBean());
       }
      }
      


      @Stateless
      @Remote
      public class BeanB implements IBeanB{
      
       @EJB
       private IBeanA beanA;
      
       public void doSomething() {
       beanA.persistSomething();
      
       throw new RuntimeException();
       }
      }
      


      The persistSomething and the doSomething methods are part of my business interfaces.

      My problem is, that the persisted entity bean isen't rolled back from the database after the RuntimeException.
      I've even tried to set the beanA's business method to TransactionAttributeType.MANDATORY so I can make sure that I'm always in the same transaction.

      Do I understand the EJB 3.0 transaction model wrong? I thought as long as my transaction spreads over one thread, then all the changes are rolled back.

      Do I need application transactions in this case?


      Thanks in advances

        • 1. Re: Transactions Rollback
          alrubinger

          Any chance your DB is set to "auto-commit", either by default or in your connection url?

          Yes, EJB application transaction rollbacks should roll back your DB transaction as well, as it's managed by the container.

          S,
          ALR

          • 2. Re: Transactions Rollback
            marook

            Thanks a lot!

            It was a database problem. I use the MySQL DB and forgot to switch to the InnoDB which supports transactions.


            Greetings
            Markus