-
1. Re: Wire XA transactions with Spring 2.5, JBossTS, Hibernate
jhalliday Oct 18, 2009 6:36 PM (in response to ketanmaydeo)You'd be better of starting with the JBoss docs, which say the JBossTS transactional driver is only for standalone use, not inside the app server. Use the app server's normal -ds.xml file with <xa-datasource> and trust it to do the right thing.
-
2. Re: Wire XA transactions with Spring 2.5, JBossTS, Hibernate
ketanmaydeo Oct 18, 2009 9:14 PM (in response to ketanmaydeo)I am supplying a code snippet here to help you understand what I'm doing.
First, I am just verifying if I can access JNDI datasource. "ds = (XADataSource) ctx2.lookup(dataSourceName); " That piece works fine.
But then I try to use transactional driver and it doesn't work.
The problem is that the transactional driver is not finding the datasource. It may have problems with the java namespace or problems with jndi in general.
javax.sql.XADataSource ods = new OracleXADataSource();
String sp = "com.sun.jndi.fscontext.RefFSContextFactory";
String file = "file:/c:/JNDI";
String dataSourceName = "jdbc/ies";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
env.put(Context.PROVIDER_URL, file);
Context ctx1 = new InitialContext(env);
((OracleXADataSource) ods)
.setURL("jdbc:oracle:thin:@ken-soradev04.ii-corpnet.com:1526:webd1");
ctx1.rebind(dataSourceName, ods);
XADataSource ds = null;
Context ctx2 = new InitialContext(env);
ds = (XADataSource) ctx2.lookup(dataSourceName);
XAConnection conn = ds
.getXAConnection("SOA_DEV1_USER", "SOA_DEV1_USER");
PreparedStatement stm = conn.getConnection().prepareStatement(
"select * from contact");
stm.execute();
stm.close();
Properties dbProps = new Properties();
dbProps.setProperty(TransactionalDriver.userName, "SOA_DEV1_USER");
dbProps.setProperty(TransactionalDriver.password, "SOA_DEV1_USER");
String url = "jdbc:arjuna:jdbc/ies";
TransactionalDriver arjunaJDBC2Driver = new TransactionalDriver();
try {
Connection connection = arjunaJDBC2Driver.connect(url, dbProps);
PreparedStatement statement = connection
.prepareStatement("select * from contact");
statement.execute();
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
This is the error I get
IBW 0 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - TransactionalDriver.TransactionalDriver ()
IBW 0 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - TransactionalDriver.TransactionalDriver ()
IBW 0 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - TransactionalDriver.connect ( jdbc:arjuna:jdbc/ies )
IBW 16 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - ConnectionImple.ConnectionImple ( jdbc/ies )
IBW 16 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - IndirectRecoverableConnection.IndirectRecoverableConnection ( jdbc/ies, SOA_DEV1_USER, SOA_DEV1_USER )
java.sql.SQLException: [com.arjuna.ats.internal.jdbc.jndierror] Could not resolve JNDI XADataSource
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:402)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.(IndirectRecoverableConnection.java:119)
at com.arjuna.ats.internal.jdbc.ConnectionImple.(ConnectionImple.java:102)
at com.arjuna.ats.internal.jdbc.ConnectionManager.create(ConnectionManager.java:141)
at com.arjuna.ats.jdbc.TransactionalDriver.connect(TransactionalDriver.java:93)
Please advise.
Thanks.
Ketan