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

    Transaction Problem

    Dalibor Kalna Newbie

      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:

      public class SimpleRemoteBean implements SimpleRemote {

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

      SessionContext ctx;

      EntityManager em;

      public void doSomething() {
      Test test = em.find(Test.class, new Long(1));

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

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

      private void neueTx() {
      Test test = new Test();