3 Replies Latest reply on May 18, 2004 2:01 PM by sesques

    How to create a UserTransaction in a JSP running on a separa

    Ignacio de Cordoba Novice

      Hi there,
      I am using JBoss as EJB Session and Entity container, but for load reasons, I use a separate tomcat in a different server tu run JSP clients. I haven't been able to create a user transaction, into which I must run several invocations to methods in JBOSS Session EJBs.
      After looking up in these forums, have tried several combinations of

      InitialContext ctx = new InitialContext();
      tx = (UserTransaction) ctx.lookup("UserTransaction");
      tx.begin();

      But I get several JNDI errors.

      Could anybody post an example of the correct way to create a User Transaction in a JSP J2EE Client?

      Thanks,
      Ignacio

        • 1. Re: How to create a UserTransaction in a JSP running on a se
          mrgarageman Newbie

          InitialContext initial = new InitialContext();
          UserTransaction transaction = (UserTransaction) initial.lookup("java:comp/UserTransaction");

          YourSessionAhome homeA = (YourSessionAHome) javax.rmi.PortableRemoteObject.narrow(initial.lookup("java:comp/env/ejb/SampleA"), YourSessionAHome.class);
          YourSessionA yourSessionA = homeA.create();

          YourSessionBHome homeB = (YourSessionBHome) javax.rmi.PortableObject.narrow(initial.lookup("java:comp/env/ejb/SampleB"),YourSessionBHome.class);
          YourSessionBHome yourSessionB = homeB.create();

          try{
          transaction.begin();
          yourSessionA.someMethod();
          yourSessionB.someMethod();
          transaction.commit();
          }
          catch(Exception ex){
          ex.printStackTrace;
          }

          public class YourSessionA implements SessionBean {
          public void someMethod(){
          System.out.println("Hope This Helps.");
          }

          // ... callbacks etc.
          }

          public class YourSessionB implements SessionBean{

          public void someMethod(){
          System.out.println("From mrgarageman.");
          }
          // .. callback etc.
          }

          • 2. Re: How to create a UserTransaction in a JSP running on a se
            Jim Newbie

            I tried this and it failed. I get the following error:
            java.lang.NoClassDefFoundError: org/jnp/server/NamingServer

            Any idea what I am doing wrong? I copied the suggested code.

            Thanks,
            Jim

            • 3. Re: How to create a UserTransaction in a JSP running on a se
              sesques Novice

              Hi,

              If you use a standalone Tomcat server, it depends on the version but it does not have a native JTA driver. Verify you have Tyrex installed and check Tomcat documentation to use it.

              Pascal