10 Replies Latest reply on Nov 4, 2003 1:39 PM by cbosquet

    How to obtain UserTransaction from client

    nishantv

      Hi all,
      I am trying to obtain reference to a UserTransaction from my client. For this I tried the following on my client:
      UserTransaction tx = (UserTransaction)ctx.lookup("javax.transaction.UserTransaction");
      I get the following exception:
      javax.naming.NameNotFoundException: javax.transaction.UserTransaction not bound

      I also tried

      UserTransaction tx = (UserTransaction)ctx.lookup("java:comp/UserTransaction");

      I get the exception javax.naming.NameNotFoundException: comp not bound

      Can anyone help me...


      regards...
      nishant

        • 1. Re: How to obtain UserTransaction from client
          nhebert


          Try ...ctx.lookup("UserTransaction");

          A quick look in the JNDI namespace lists it as
          such in the Gobal namespace...

          http://localhost:8082

          then click "service=JNDIView"

          then click button "list"

          Cheers,

          Noel.

          • 2. Re: How to obtain UserTransaction from client
            nishantv

            Hi.
            Thanks for that reply.
            I tried using ctx.lookup("UserTransaction");
            However I get the exception:

            javax.naming.NameNotFoundException: UserTransaction not bound.

            A looked into JNDI namespace, clicking on
            "service=JNDIView" shows :

            MBean Name: DefaultDomain:service=JNDIView
            MBean Java Class: org.jboss.naming.JNDIView

            I guess this means that I need to bind "UserTransaction" with the JNDI namespace.

            Do you know how to do this?
            I was trying with some setting in the jboss.jcml file but could not succeed.
            This is the kind of setting I did:
            <!-- Transactions -->

            UserTransaction
            300


            I now tried to lookup UserTransaction :
            UserTransaction tx=(UserTransaction) ctx.lookup("UserTransaction");

            but I get exception:
            javax.naming.NameNotFoundException: UserTransaction not bound.

            Do you know the precise setting for this.


            regards,
            Nishant.



            • 3. Re: How to obtain UserTransaction from client
              nhebert

              Nishant,

              I do not want to fall into the "works for me!" trap...
              Could you send me the code snippet so I can put
              eyeballs to it?

              Send to: nhebert@dingoblue.net.au

              I ran through a couple of different code variations
              from what you last wrote. Alas, they worked for
              me. ;-)

              FYI, I am running with JBoss 2.4.0. As I write this
              I am downloading 2.4.1. We see if something breaks.

              Cheers,

              Noel.

              • 4. Re: How to obtain UserTransaction from client
                prashu

                Hi hebert/Nishant,
                I m havin the same problem of getting
                "UserTransaction name not bound".
                FYI, I've attached the complete program.
                Can u pls tell me the soln.
                As u told earlier, the following statement
                utx = (UserTransaction)ctx.lookup("UserTransaction");
                still gives the same error !!!!
                Also, I've done as ur info, seen http://localhost:8082
                clicked on "service=JNDIView", & then clicked button "list"
                Its showing only 2 entries of MBean as nishant told u earlier.
                By pressing List, what does it do exactly ????
                Pls note that I m using JBoss v2.2.2 with embedded tomcat
                v3.2.2 with MySql v3.23.41 as backend on Windows 98 OS.
                Can u pls tell me where i m goin wrong ??? Pls cc to me
                at prashantssarode@yahoo.com

                Thanks & Regards,
                Prashant

                • 5. Re: How to obtain UserTransaction from client
                  nishantv

                  Hi.
                  Well, I downloaded JBoss 2.2, JBoss 2.2.2, JBoss 2.4.1.
                  I executed all the three servers and looked up the JNDI namespace through the link:
                  http://localhost:8082/
                  I found that, only JBoss 2.4.1 has "UserTransaction" defined and that too in its Global Namespace. This means using JBoss 2.4.1 you can get the handle to UserTransaction using:
                  UserTransaction userTx =(UserTransaction) ctx.lookup("UserTransaction");

                  That means only JBoss ver 2.4 and above supports User transaction.
                  Well since I am using JBoss 2.2.2 (which happens to be a stable version right now), I am trying other ways to get around this problem.
                  Btw, herbert you are using JBoss2.4.0. Did you run into any specific problems which indicated that JBoss2.4.0 is unstable?

                  thanks.
                  Nishant.

                  • 6. Re: How to obtain UserTransaction from client
                    lamx0009

                    Hi, thanks for the tip, I downloaded 2.4.1 version and got the UserTransaction from jndicontext alright. But I still have the following problem when I do this:

                    UserTransaction transaction = (UserTransaction)ctx.lookup("UserTransaction");

                    java.lang.ClassCastException: javax.naming.Reference
                    at com.apldbio.arrays.test.XSessionBeanTestClient1.main(XSessionBeanTes
                    tClient1.java:133)

                    when I print out result of ctx.lookup("UserTransaction"), I get: Reference Class Name: org.jboss.tm.usertx.client.ClientUserTransaction

                    and when I take a look at the source code for ClientUserTransaction, it shows it does implements UserTransaction.

                    So, I don't know why the ClassCastException occurred.

                    Any idea is appreciated,
                    Joseph

                    • 7. Re: How to obtain UserTransaction from client
                      lamx0009

                      Ok, With JBoss2.4.3. Everything works fine now. User Transaction is bound to the global jndi namespace with the name "UserTransaction". (So, lookup("UserTransaction") would do it)

                      However, there is still one minor strange thing about it. That is, if we use it on the client side. We need to specify "java.naming.factory.initial" and "java.naming.provider.url" as system properties. Otherwise, even though we got the initialContext in the code and have UserTransaction looked up already. When we do a userTransaction.begin(), we will get this complain:

                      javax.transaction.SystemException: java.lang.RuntimeException: UT factory lookup failed: javax.naming.
                      NoInitialContextException: Need to specify class name in environment or system property, or as an appl
                      et parameter, or in an application resource file: java.naming.factory.initial
                      at org.jboss.tm.usertx.client.ClientUserTransaction.begin(ClientUserTransaction.java:108)
                      at com.apldbio.arrays.coloma.persist.testclient.XSessionBeanTestClient1.doX(XSessionBeanTestCl
                      ient1.java:88)
                      at com.apldbio.arrays.coloma.persist.testclient.XSessionBeanTestClient1.main(XSessionBeanTestC
                      lient1.java:169)

                      Anyway, I think this is strange because we already got the UserTransaction through a jndiContext that already has the factory and providerURL specified! why do we still need to specify it as system properties?

                      -Joseph

                      • 8. Re: How to obtain UserTransaction from client
                        lperlz

                        Hi lamx0009,

                        I get the same exception, but i'm with jboss 3.0.1
                        so, if you find the solution, please explain it here.

                        thanks

                        • 9. Re: How to obtain UserTransaction from client
                          pkinwork

                          One of achieveing this is by using NamingAlias Service.
                          You can define a NamingAlisa-service.xml file in deploy directory with the following entry.




                          UserTransaction
                          javax.transaction.UserTransaction





                          in code

                          initialContext.lookup("UserTransaction");
                          or
                          initialContext.lookup("javax.transaction.UserTransaction");

                          can be used. This was tested in 3.2.1. I am not sure about the earlier version

                          • 10. Re: How to obtain UserTransaction from client
                            cbosquet

                            Hello,
                            I am using jboss 3.2.1 i have the same probleme from the client side... have a look to the method ClientUserTransaction.createSession() :
                            00269 private synchronized void createSession()
                            00270 {
                            00271 // Destroy any old session.
                            00272 if (session != null)
                            00273 destroySession();
                            00274
                            00275 try {
                            00276 // Get a reference to the UT session factory.
                            00277 UserTransactionSessionFactory factory;
                            00278 factory = (UserTransactionSessionFactory)new InitialContext().lookup("UserTransactionSessionFactory");
                            00279 // Call factory to get a UT session.
                            00280 session = factory.newInstance();
                            00281 } catch (Exception ex) {
                            00282 throw new RuntimeException("UT factory lookup failed: " + ex);
                            00283 }
                            00284 }
                            we can see that a new InitialContext is created without any property : from the client side the initialContext is unable to find the UserTransactionSessionFactory objet...
                            An issue is to setup client system properties properly for InitialContext lookup.
                            That's all
                            (sorry for my poor english)

                            Charles