0 Replies Latest reply on Nov 25, 2002 12:49 PM by fox

    Please advice on using JTA, JNDI and Session.getUserTransact

    fox Newbie

      Hi all jboss guru

      It is highly appreciated somebody can share with me your knowledge in following questions
      l did the test using jboss 2.4.8 and tomcat 4.

      1) Below is my test program (there may be some typo)
      l am quite confused that 2nd invocation of "GetUserTransaction" function seems to return the
      same transaction context which is started by 1st invocation. Why ? Is it because tx context
      will be associated with the thread where it is created. Subsequent call of JNDI to look up the UserTransaction
      will alway return the tx context assoicated with the thread, if exist ? However, it seems to me
      that J2EE does explicitely specify this requirment. Is this a unique feature of JBOSS or all app server
      behave in this way ? Please comment on this.

      <%!
      public UserTransaction GetUserTransaction(){
      InitContext ctx = new InitContext();
      return (UserTransaction)ctx.lookup("java:comp/UserTransaction");
      }

      %>

      <%
      UserTransaction tx = GetUserTransaction();
      tx.begin();
      UserTransaction tx2 = GetUserTransaction();
      if(tx2.getStatus() == Status.ACTIVE_TRANSACTION){
      out.println("active transaction");
      }

      %>

      2) Let's say, l create a bean-managed tx stateful session bean. Within the methods of the bean,
      instead of using "sessioncontext.getUserTransaction" to get "UserTransaction" and start tx, l using
      above approch of using JNDI to look up "UserTransaction" interface and start tx without ending the tx.
      Then in another methods of same stateful session bean, l use "sessioncontext.getUserTransaction" to
      control tx. Will the same tx context returned by the invocation of "sessioncontext.getUserTransaction" ?
      It seems to me that EJB spec explicitely specify same tx context should always be returned to
      stateful bean, if exist. Is it held true for a mix of JNDI approach and "sessioncontext.getUserTransaction".
      Please comment on it !

      thx and rgds
      fox