2 Replies Latest reply on Apr 9, 2002 8:15 AM by sanepid

    Distributted transaction management - Possible bug ?

    sanepid

      Hello,
      I'll try to go straight to the point: one of the valid EJB 2.0 scenarios for distributed transaction management is so-called "client-managed", where the transaction is started and committed by the client as follows

      UserTransaction ut = initialContext.lookup("UserTransaction");
      ut.begin();
      // invoke EJB business methods
      ut.commit();

      It's the apps responsibility to enlist any resource who wants to participate in the distributed transaction because, according to the specification , the transactional context is transmitted from the client to the application server.
      Let's consider further the client being Tomcat running in a separate VM.
      As far as I know, Tomcat uses it's own jndi repository.
      Here is the point though: when I make the lookup from the client(tomcat), I create the initial context with jboss parameters. So far everything is fine, and a valid ut is returned from JBoss. When I call the ut.begin(), the ClientUserTransaction class (implementation of the UserTransaction) tries to get a reference to the UserTransactionSessionFactory with the following code:

      UserTransactionSessionFactory factory;
      factory = (UserTransactionSessionFactory)new InitialContext().lookup("UserTransactionSessionFactory");

      Again, we are in the client and the no-argument constructor for InitialContext will look for the Tomcat initial context instead of the JBoss context, where UserTransactionSessionFactory is actually located. Hence the error saying "the object does not belong to this context"

      Maybe everything comes from my misunderstanding of the EJB specifications and the transactional context cannot be transmitted between Tomcat and JBoss if they run in separate VMs. In this case, why the UserTransactionSessionFactory is registered under global namespace in JBoss's JNDI?
      If this is indeed an unexpected behaviour, would there be any chance to specify a property file in order to access the desired repository? (I tried to copy the jndi.properties with jboss parameters under the tomcat classpath without success)
      I am using Tomcat 4 and JBoss 3.0 alpha with JDK 1.4 beta 3

      Thanks

        • 1. Re: Distributted transaction management - Possible bug ?
          davidjencks

          I haven't tried either of these:

          1. turn off Tomcats jndi entirely.

          2. In your web app in an appropriate place, include jndi.properties pointing to jboss jndi. With luck, this will be used by all of your code to get InitialContexts from jboss rather than Tomcat using new InitialContext()

          Who knows, one of these might work.

          • 2. Re: Distributted transaction management - Possible bug ?
            sanepid

            Hello David,
            thanks for reply
            I forgot to specify that I actually need tomcat jndi for database access (the datasource is retrieved in a similar way with jboss). I'll try to keep the jboss jndi as default and specify all tomcat parameters and if this won't work, I'll move the transaction management from the servlet into an ejb (on the client side I don't have resources participating to transaction; all are on apps side)
            Thanks