1 Reply Latest reply on Mar 15, 2005 9:11 AM by Scott Stark

    UserTransaction and JNDI in JBoss 4

    Valentin Pascaru Newbie

      Hi
      When I try to get an UserTransaction in JBoss using the standard JNDI name "java:comp/UserTransaction" an exception is thrown (NameNotFoundException or something like this). Anyway, the needed UserTransaction object can be found at "/UserTransaction" JNDI name. Is there any way to get the UserTransaction object in JBoss 4 using the standard J2EE location? ("java:comp/UserTransaction"). In JBoss's manual it says that the deployer should automatically link the "java:comp/UserTransaction" name to an "/UserTransaction" :

      " When components are deployed in an embedded web server, the deployer will make a JNDI link from the standard java:comp/UserTransaction ENC name to the global UserTransaction binding so that the web components can lookup the UserTranaction instance under JNDI name as specified by the J2EE."

      Even so, I cannot use the standard "java:comp/UserTransaction" string. Do I miss something?

      Thanks in advance,
      Valentin Pascaru - software developer

        • 1. Re: UserTransaction and JNDI in JBoss 4
          Scott Stark Master

          There is a unit test which does this exact lookup:

           // Get an initial context
           InitialContext ctx;
           try {
           ctx = new InitialContext();
           } catch (NamingException ex) {
           throw new ServletException("Unable to get an InitialContext", ex);
           }
          
           // Get the UserTransaction
           UserTransaction ut;
           try {
           ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
           } catch (NamingException ex) {
           throw new ServletException("Unable to lookup UserTransaction", ex);
           }