Discussions

EJB design: Session Facade Transaction

  1. Session Facade Transaction (6 messages)

    Hi,
       I am using Session Facade pattern where Stateless Session Beans interact with CMPs. I have set the Transaction Attribute for both Stateless Session Bean and CMP as "Required". My problem is, if I get any exception in Stateless Session Bean method, transaction is not getting rolled back. That is, I have a requirement of updating two tables from a Session Bean. So I am calling my 1st CMP from my session bean. After that I have some code for implementing Business Logic which gets excuted. Then I am calling 2nd CMP for updation. But if I get any exception in Business Logic implementation, the 1st CMP's updation to DB doesnot get rolled back. It gets committed. Is there anything I have missed out? Do I need to use XA connection pool for transactions? Please let me know.
    Thanks
    Prasanna

    Threaded Messages (6)

  2. session facade[ Go to top ]

    Hi,

    Are you calling both the methods of CMP in same method of session bean?,if you are doing so then it should work,If you are caling in different methods then every time it will open new transcation.

    Regards,
    Manish
  3. session facade[ Go to top ]

    Hi,Are you calling both the methods of CMP in same method of session bean?,if you are doing so then it should work,If you are caling in different methods then every time it will open new transcation.Regards,Manish
    Yes, I am calling both the methods of CMP in same method of Stateless Session Bean. I am using JBOSS 3.0.6. Should I use XA connection pool? I am bit confused. Please help me.

    Thanks,
    Prasanna
  4. session facade[ Go to top ]

    Are you doing setRollbackOnly() on SessionContext when you catch the Exception???
  5. session facade[ Go to top ]

    No,
    Can u please let me know how to handle that Exception? I just want the transaction to get rolled back in case of any exception. Could please help me.

    Thanks in Advance,
    Prasanna
  6. session facade[ Go to top ]

    public class LossFacadeEJB implements SessionBean {
       private SessionContext sc = null;
       public void ejbCreate() {
       }
       public void setSessionContext(SessionContext sc) {
          this.sc = sc;
       }
       protected ResponseObject perform(Event event) {
         ResponseObject response = null;
         try {
           entity1.doSomething();
           entity2.doSomething();
         } catch (Exception e) {
         // Si se genera una excepcion se setea para rollback
           sc.setRollbackOnly();
           e.printStackTrace();
           response = new ResponseObject("Error");
         }
         return response;
       }
    }
  7. session facade[ Go to top ]

    Yes, it worked. Thank You very much!!!

    Regards,
    Prasanna