This content has been marked as final.
Show 3 replies
-
1. Re: JBoss never commits using UserTransaction
mmusgrov Jan 16, 2009 4:48 PM (in response to mauricioariel)The context lookup for UserTransaction actually returns a proxy for the transaction running in the server so you can call tx.commit() on it.
-
2. Re: JBoss never commits using UserTransaction
mauricioariel Jan 22, 2009 1:04 PM (in response to mauricioariel)"mmusgrov" wrote:
The context lookup for UserTransaction actually returns a proxy for the transaction running in the server so you can call tx.commit() on it.
Thanks mmusgrov, that works fine.
Now I advanced one more step obtaining the datasource by JNDI and updating the database from the client:
try {
Context ctx = new InitialContext();
BeanServiceRemote beanService = (BeanServiceRemote)ctx.lookup("jndi/BeanService");
UserTransaction tx = (UserTransaction) ctx.lookup("UserTransaction");
tx.begin();
DataSource ds = (DataSource) ctx.lookup("my.DataSource");
Connection conn = ds.getConnection();
PreparedStatement stmt = conn.prepareStatement("insert into MyTable (ID, NAME) values (1, 'name')");
stmt.execute();
beanService.create();
tx.commit();
The problem is "tx.commit();" only commits the ejb updates, not the client updates.
I tried adding:
conn.setAutoCommit(false);
conn.commit();
and It works but If I commit the connection, then I can 't rollback it, in case the ejb or the tx.commit() fails.
It seems, the TransactionManager doesnt manage client updates.
BTW, Im using JbossAS 4.3 default installation, and an Oracle xa-datasource. -
3. Re: JBoss never commits using UserTransaction
mmusgrov Jan 24, 2009 6:57 AM (in response to mauricioariel)Ah that is not a trivial task you are trying to execute. You will need to install the JTS version of the transaction service on both the client and server.
There is a link on the WIKI that goes through an example of how to do it:
https://www.jboss.org/community/docs/DOC-13179
Good look with it.