aspose file tools
The moose likes Distributed Java and the fly likes Accessing UserTransaction object on JBoss 4.0.1 from remote client Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Reply Bookmark "Accessing UserTransaction object on JBoss 4.0.1 from remote client" Watch "Accessing UserTransaction object on JBoss 4.0.1 from remote client" New topic
Author

Accessing UserTransaction object on JBoss 4.0.1 from remote client

suparna.venkat
Greenhorn

Joined: Oct 05, 2005
Posts: 7
Hi,

Can anyone help me out here?

I am using JBoss 4.0.1 and I've deployed a Datasource "Test" to connect to Postgres database.

This is what my java client which is running in JVM outside JBoss.

1. Lookup "UserTransaction" object in JBoss namespace.
2. Lookup "Test" datasource in JBoss namespace. (With JBoss 3.2.x it is not possible, it's possible only in JBoss 4.0.x by setting "<use-java-context>false</use-java-context>" in -ds.xml to deploy dataosure.)
3. Begin UserTransaction, Get connection object and do some database updates & either commit or rollback usertransaction.
4. But UserTransaction is not working. My database updates are always committed.
I tested the same thing in EJB deployed on the JBoss and it works fine. The only problem is when I control the user transaction from outside JBoss JVM. I get no errors/exceptions but it doesnt work.

Here is the snippet of code.

***********************************************
InitialContext ctx = new InitialContext();
Object o1 = ctx.lookup("AgileITPTest");
DataSource datasource = (DataSource) PortableRemoteObject.narrow(o1, DataSource.class);
Object o = (UserTransaction) ctx.lookup("UserTransaction");
UserTransaction userTransaction = (UserTransaction)PortableRemoteObject.narrow(o, UserTransaction.class);

userTransaction.begin();
Connection conn = datasource.getConnection();
stat = conn.createStatement();
String sql_Outer = "insert into transac_order values(6421)";
stat.executeUpdate(sql_Outer);
userTransaction.rollback();
conn.close();
} catch(Exception sle) {
sle.printStackTrace();
}
**********************************************************


Thanks in advance,
Suparna
suparna.venkat
Greenhorn

Joined: Oct 05, 2005
Posts: 7
Hi,

I've found that we can not control transaction from the client side on the UserTransaction object looked up from JBoss.(Though we can start from the client, we can commit or rollback only on server side).

http://www.cenqua.com/clover/eg/jboss/report/org/jboss/test/testbean/bean/BMTStatefulBean.html

But does any other appserver(Websphere/Weblogic) support that?


Thanks,
Suparna
suparna.venkat
Greenhorn

Joined: Oct 05, 2005
Posts: 7
Sorry that was a wrong URL by mistake.
Correct one:
http://docs.jboss.com/jbossas/admindevel326/html/ch4.chapt.html
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
It's generally a bad idea to start transactions from a client. Your client should invoke a bean's method in the container to do the DB update, and it is this method which should run in a transaction.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
suparna.venkat
Greenhorn

Joined: Oct 05, 2005
Posts: 7
Hi,

Thanks for your reply. But the requirement says that I should use commit & rollback on UserTransaction object in the client. Is there anyother alternative to achive this using anyother Application Server other than JBoss?

Thanks,
Suparna
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Accessing UserTransaction object on JBoss 4.0.1 from remote client
 
Similar Threads
EJB transaction issue
Problems in Websphere AppServer5.1(the latest version)
Returning null DataSource object in JBoss 4.0.3
UserTransaction object in remote client
lookup on UserTransaction