4 Replies Latest reply on Nov 29, 2013 2:00 PM by memyself141

    How to resolve UserTransaction from another JBoss server in JBoss 5.1

    memyself141

      Hi,

       

      I have a 3rd party tool (EJB 2.0) deployed on remote JBoss 5.1.  I have to use these EJBs using the client code (a plain servlet deployed on my local machine's JBoss 5.1) somewhat like this :

       

      IntitialContext context = new initialContext(RemoteServerEnv.prop);

      UserTransaction ut = (UserTransaction)context.lookup("UserTransaction");

      ut.begin();

      callSomeMethodOnEJB1();

      callSomeMethodonEJB2();

      if(errorFound)

      {

           callFinalMethod();

           ut.rollback();

      }

       

      The above code works fine when written in a POJO client (inside a plain main() method). The transaction (the changes made by MethodOnEJB1 and 2) gets rolled back in case of 'errorFound' being true.

       

      However, the same code does not rollback the transaction when I run it from my client web-app which is also deployed on JBoss 5.1 (local server on my machine, not the same as the remote server where EJBs are deployed).

       

      The difference that I found out between the 2 codes is that

      1. in POJO client, the InitialContext.lookup("UserTransaction") returns an instance of ClientUserTransaction while

      2. in JBoss client, the InitialContext.lookup("UserTransaction"); returns an instance of ServerVMClientUserTransaction.

       

      I am unable to understand why am I getting ServerVMClientUserTransaction instead of ClientUSerTransaction. I am looking up the remote server but it is returning me the UserTransaction from my local server (cause ServerVMClientUserTransaction is returned when looking up "UserTransaction" on the same JVM)

       

      Is there any way that I can resolve this....

       

      Many thanks.

       

      Message was edited by: AAYUSH SINGHAL

        • 1. Re: How to resolve UserTransaction from another JBoss server in JBoss 5.1
          wdfink

          For such scenario you should change the Tx system from JTA to JTS.

          There is a ant script to change that (it has worked for me years ago) in docs/examples/transactions see the README file.

           

          After that you the transaction is propagated to the remote server and will follow commit/rollback.

           

          In my understanding the container decide what you get back if you do a lookup, as you are in a managed environment you get the ServerVM* from the server.

          At client side this is a implementation which can not run in a managed environment.

          • 2. Re: How to resolve UserTransaction from another JBoss server in JBoss 5.1
            memyself141

            Thanks Wolf-Dieter Fink. This is what other guys at the forum have told me in the Transaction Space (can't thank Tom and Michael enough) i.e. to change to JTS from JTA. I have changed my local machine's JBoss to use JTS using that very script. I have raised a request to get the remote JBoss to use JTS( I do not have the permissions to do that). But I just want to confirm that this is a normal case that you get ServerVMClientUserTransaction when doing a lookup on "UserTransaction" from a JBoss client... I just hope that I am not doing something wrong here....

            • 3. Re: How to resolve UserTransaction from another JBoss server in JBoss 5.1
              wdfink

              You might use a 'fake' application with another server which you can change to JTS to check that the Tx work as you expect.

              I think the problem is that you have to do the change in a productional environment and everybody need to be sure that this will not have bad impacts.

              • 4. Re: How to resolve UserTransaction from another JBoss server in JBoss 5.1
                memyself141

                I understand what you are saying but this is a 3rd party owned tool so we don't have much leverage to 'try' things out.... But I've raised the request already... Let's just hope it works out...