2 Replies Latest reply on Dec 13, 2005 3:40 AM by Jacek Olszak

    One more question about transactions

    Jacek Olszak Newbie

      Last few days I was thinking about transactions which can be manipulated by the client. But till now I've no good solution. I want to have a bean which transactions can be started, rollback and commit by the client. I want to have a solution, where client can rollback only last transaction (not everything).

      I've created simple stateful bean:

      @TransactionManagement(TransactionManagementType.CONTAINER)
      @FlushMode(FlushModeType.NEVER)
      @Stateful
      public class TransactionsStateful implements TransactionsStatefulLocal {
      
       @PersistenceContext(unitName = "ksiegi", type = PersistenceContextType.TRANSACTION)
       protected EntityManager em;
      
       @Resource
       protected SessionContext ctx;
      
      
       public void commit() {
       em.flush();
       }
      
       @TransactionAttribute(TransactionAttributeType.REQUIRED)
       public void rollback() {
       throw new RamzesException("Rollback");
       }
      
      
       private short tmpId = 0;
      
       @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
       public void a() {
       TypDzial typ = new TypDzial();
       typ.setNazwa("zooo32");
       em.persist(typ);
       tmpId = typ.getId();
       }
      }
      


      I run this code using:

      local.a();
      try {
      
       local.rollback();
      } catch (RamzesException e) {
      }
      local.commit();
      

      But the data was stored, even though I've thrown an exception using rollback method :( Yes, I know that I've catched the exception but client will be executing methods this way - he can rollback only last transaction, not all.

      Is there any chance to rollback only last transaction?