1 Reply Latest reply on Jun 16, 2003 3:13 PM by lafr

    Create new transaction for a method of a SSB

    lvhuyen

      I have a Stateless Session Bean named ManagerEJB with a method name insert(..), in which, I create 3 entities AEJB, BEJB and CEJB. But when I fail to create a BEJB (with an exception I catched), in my database, still have a new row of table A.
      In my ejb-jar.xml file, I have had the following declaration:
      <container-transaction>

      <ejb-name>ManagerEJB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>

      All of my entities bean and session bean are CMT.

      Please help me!
      Thanks

        • 1. Re: Create new transaction for a method of a SSB
          lafr

          Enhance ManagerEJB with the following field and method:

          private javax.ejb.SessionContext sessionCtxt = null;

          public void setSessionContext( javax.ejb.SessionContext ctxt )
          {
          this.sessionCtxt = ctxt;
          }

          in catch-block of the exception:
          this.sessionCtxt.setRollbackOnly();

          This will cause a rollback instead of a commit when leaving the SessionBean method.