0 Replies Latest reply on Sep 22, 2006 8:51 AM by David LE SAULNIER

    JTA User Transaction problems with J2EE across 2 Sessions Be

    David LE SAULNIER Newbie

      Hello,

      Under jboss-4.0.4.GA, I have two EJB Session StateLess.

      In EJB 1, I begin a JTA User Transaction, call a method of EJB 2 and then commit the transaction.

      The problem is that the JTA User Transaction initied in EJB 1 is not Active in EJB 2.

      I read a post on java.sun.com about the same kind of problem:
      http://forum.java.sun.com/thread.jspa?forumID=48&threadID=349443

      Could you help me ?

      Arnaud CHOTARD

      ###### EJB 1 #########

      /**
      * @ejb.interface-method view-type = "remote"
      */
      public void method1() {
      UserTransaction ut = null;
      try {
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
      properties.put(Context.PROVIDER_URL, "localhost");

      InitialContext ic = new InitialContext(properties);

      EtablissementBusinessServiceHome home = (EtablissementBusinessServiceHome) ic.lookup("tmsi/business/reference/EtablissementBusinessService");
      EtablissementBusinessService service = (EtablissementBusinessService) home.create();

      ut = this.sessionContext.getUserTransaction();

      ut.begin();

      System.out.println("EJB1 Transaction Active ? " + (ut.getStatus() == Status.STATUS_ACTIVE) + "(" + ut.getStatus() + ")");

      service.method2();

      ut.commit();

      } catch (Exception ex) {
      if (ut != null) try { ut.rollback(); } catch (Exception e) {}
      ex.printStackTrace();
      }
      }

      ###### EJB 2 #########

      /**
      * @ejb.interface-method view-type = "remote"
      */
      public void method2() {
      try {

      UserTransaction ut = this.sessionContext.getUserTransaction();

      System.out.println("EJB2 Transaction Active ? " + (ut.getStatus() == Status.STATUS_ACTIVE) + "(" + ut.getStatus() + ")");

      } catch (Exception ex) {
      ex.printStackTrace();
      }
      }

      ###### Console Trace #########

      12:39:09,570 INFO [STDOUT] EJB1 Transaction Active ? true(0)
      12:39:09,570 INFO [STDOUT] EJB2 Transaction Active ? false(6)