-
1. Re: transaction from the client side
dlaidlaw Sep 22, 2003 2:55 PM (in response to volkanyildiz)Yes.
Assuming your client code is a servlet or standalone program get a JNDI context with:
InitialContext jndi = new InitialContext();
or InitialContext jndi = new InitialContext(map);
where map specifies how to connect to JNDI.
Then use the jndi object to get a UserTransaction, like:
UserTransaction utx = (UserTransaction) jndi.lookup("UserTransaction");
After that you can use the methods on the utx object to start, commit and rollback the transaction. All transacted methods you call in betwee start() and commit() or rollback() will happen inside the scope of the UserTransaction utx.
More info on UserTransaction and getting a JNDI context can be found in the manuals or in a good EJB book. -
2. Re: transaction from the client side
volkanyildiz Sep 22, 2003 11:25 PM (in response to volkanyildiz)Then i got the following exception.Any idea?
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 applet parameter, or in an application resource file: java.naming.factory.initial -
3. Re: transaction from the client side
dlaidlaw Sep 23, 2003 8:58 AM (in response to volkanyildiz)You are not getting a correct JNDI InitialContext. Try creating a file called jndi.properties in your classpath for the client code and add the following lines to it:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
You will have to change localhost to the hostname running JBoss if it is not the same host as the client code. -
4. Re: transaction from the client side
volkanyildiz Sep 23, 2003 10:26 AM (in response to volkanyildiz)I have tried this and it gave me the same exception. I'm using version 3.0.6. May it be something about it.
Properties prop = new Properties();
prop.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
prop.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
prop.put("java.naming.provider.url", "localhost:1099");
InitialContext jndi = new InitialContext(prop);
UserTransaction utx = (UserTransaction) jndi.lookup("UserTransaction");
System.out.println("start");
utx.begin(); -
5. Re: transaction from the client side
dlaidlaw Sep 23, 2003 12:45 PM (in response to volkanyildiz)That is possible, I don't have that version. But it is more likely that you don't have the client jars for jboss in your classpath. Including the jndi jars. Try adding some jars from the JBOSS_HOME/client directory to your classpath.