4 Replies Latest reply on Aug 29, 2005 4:40 AM by bmhardy

    rollback

    Kabir Khan Master

      Transactions basically work as in previous versions of EJB

        • 1. Re: rollback
          bmhardy Newbie

          In ejb2.1 there was a setSessionContext method. The Container set the context. In any method one could use the context (ctx) to say ctx.setRollbackOnly. How could you do something similar using the ejb3.0 preview? Also in ejb2.1 when a method threw and EJBException a rollback occured automatically I believe. What would be the analogous thing to do when using ejb3.0 preview?

          • 2. Re: rollback
            Kabir Khan Master

            In EJB3, you can make sure that the contaner injects the sessioncontext into your sessionbean, by either annotating the setter:

            @Inject public void setSessionContext(SessionContext ctx) {
             this.ctx = ctx;
            }
            


            or the member variable directly:

            @Inject SessionContext ctx;
            


            • 3. Re: rollback
              bmhardy Newbie

              This doesn't work in the latest ejb 3.0 that comes with as 4.0.3RC2.
              What should we use now?

              Thanks

              • 4. Re: rollback
                bmhardy Newbie

                I think it goes like this:

                private @Injected EntityTransaction tx;
                try {
                ...
                } catch (Exception ex)
                {
                tx.rollback();
                }