3 Replies Latest reply on Oct 23, 2006 10:24 AM by dkalna

    Transaction Problem

      Hello, please help me, I'm stuck... my code is below, simple Stateless EJB with teo methods, both are REQUIRES_NEW annotated, in first one doSomething I read one row from DB, then I call second method neueTx, which I suppose will run in separate TX. Inside neueTX I call setRollbackOnly() to mark this TX for rollback, so new row (2, Jane) will be rolled back. Now back in doSomething I try to write changes for first row, but then I get following Exception: EntityManager must be access within a transaction

      Am I missing something simple?

      Thanks a lot

      Here is my code:

      @Stateless
      @Remote(value=SimpleRemote.class)
      public class SimpleRemoteBean implements SimpleRemote {

      static Logger logger = Logger.getLogger(SimpleRemoteBean.class);

      @Resource
      SessionContext ctx;

      @PersistenceContext
      EntityManager em;

      @TransactionAttribute(value=TransactionAttributeType.REQUIRES_NEW)
      public void doSomething() {
      Test test = em.find(Test.class, new Long(1));

      neueTx(); // should be running in separate TX, or not?

      test.setName("Lukas");
      em.merge(test); // I expect this to be writen in DB successfully
      }

      @TransactionAttribute(value=TransactionAttributeType.REQUIRES_NEW)
      private void neueTx() {
      Test test = new Test();
      test.setId(2);
      test.setName("Jane");

      em.persist(test);

      ctx.setRollbackOnly();
      }

      }

        • 1. Re: Transaction Problem
          wolfc

          Only when you run the neueTx method through a business interface will it get a new transaction. Directly calling the method from within the bean won't trigger any tx features.
          Please try:

          ctx.getBusinessObject(SimpleRemote.class).neueTx();


          • 2. Re: Transaction Problem

            Hello wolfc, thanks for replay...

            i have implemented it, now I get following exception:

            java.lang.IllegalStateException: Not implemented

            I'm using JBoss-4.0.4GA... is it possible that this feature is not implemented, or something else?

            Thanks a lot
            Dalibor

            • 3. Re: Transaction Problem

              ok, I've found the problem, after I installed EJB3.0-RC9 problem 'Not Implemented' disappeared.

              Bye
              Dalibor