1 Reply Latest reply on May 8, 2007 6:29 PM by wolfc

    Inner transection in EJB3 using annotation (in stateless ses

    niityasir

      HI

      I am facing problem in implementing inner transaction. I am using JBoss, NetBeans IDE and EJB3.0 . For transaction management I want to use annotations(like TransactionAttributeType.REQUIRES_NEW or any other). I want to implement some sort of inner transation. In my method of session bean I am performing following task in sequence.

      @Stateless
      public class JVTOSSOMSessionBean implements JVTOSSOMSessionRemote, JVTOSSOMSessionLocal, JVTOrderManagementSession {
      
       @PersistenceContext
       private EntityManager em;
       RequestOMValue objRequestOMValue;
       /** Creates a new instance of JVTOSSOMSessionBean */
       public JVTOSSOMSessionBean() {
       }
      
       public RequestOMKey createAndStartRequestOMByValue(RequestOMValue requestOMValue) throws OssIllegalArgumentException, RemoteException, ObjectNotFoundException {
       boolean isSuccess=true;
       RequestOMKey mdnOrderKey=requestOMValue.updateOrder();
       isSuccess=requestOMValue.processOrder(this.em);
       if(isSuccess==true){
       requestOMValue.updateSuccessOrder();
       } else{
       requestOMValue.updateFailOrder();
       }
       return mdnOrderKey;
       }
      




      Now I want to achieve behavior that ,if any exception occurs in processOrder method then only tasks performed in processOrder are rollback.

      Curretly if any exception occur then all tasks roll back , which also include tasks that i perform in updateSuccessOrder , updateFailOrder , updateOrder and processOrder.

        • 1. Re: Inner transection in EJB3 using annotation (in stateless
          wolfc

          Create a new method processOrder and annotate it with transaction type REQUIRES_NEW.

          @TransactionAttribute(REQUIRES_NEW)
          void processOrder(RequestOMValue value)
          {
           value.processOrder(this.em);
          }

          Then call it via getBusinessObject.
          ctx.getBusinessObject(JVTOSSOMSessionLocal.class).processOrder(requestOMValue);