Hello All
I have two resources - one JMS and another Database, both should participate in a global transaction. However, the client is a standalone!
I'll explain here usng code bits.
I create an instance of transaction manager (basically JBoss's TM) using the static method
Code:
/*
* Create a Transaction Manager
*/
tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
Now I do the bits such as reating a transaciton, enlisting the resources:
Code:
/*
* Strat the transaction manager
*/
if (tm.getTransaction() == null) tm.begin();
/*
* Obtain a reference to the transaction object
*/
Transaction tx = tm.getTransaction();
/*
* Enlist the resources
*/
logger.info("Enlisting resources");
tx.enlistResource(msgRes);
tx.enlistResource(sybaseXaResource);
Now, I publish messages and update the datbase and then commit to see if changes have taken place.
Code:
/*
* publish the message
*/
mp.send(txtMsg);
/*
* Use the statment to insert the values into table
*/
logger.info("Inserting values into table");
int i = stmt.executeUpdate("INSERT INTO XATEST VALUES('test-"+ System.currentTimeMillis() / 1000 + "')");
/*
* Unless you commit, the changes are not going to be affected
*/
tm.commit();
logger.info("Transaction committed. Check your data");
Everything works perfectly in a transaction until this point. Next thing is I've introduced hibernate. Just after the DB and before the commit, the following code is added:
Code:
Session hibSession = HibernateUtil.getSessionFactory().openSession();
// org.hibernate.Transaction txn = hibSession.beginTransaction();
TwoPhaseTestVO vo = new TwoPhaseTestVO();
vo.setName("MK" + System.currentTimeMillis() / 1000);
hibSession.save(vo);
/*
* Unless you commit, the changes are not going to be affected
*/
tm.commit();
Howerver, the msg and db works as expected but not the hibernate block. I am not sure what's happening here.
Here's my Configuration() creation code:
Code:
try {
Configuration cfg = new Configuration().addClass(com.xyz.platform.jms.xa.hibernate.TwoPhaseTestVO.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.SybaseDialect")
.setProperty("hibernate.connection.driver_class","com.sybase.jdbc3.jdbc.SybXADataSource")
.setProperty("hibernate.connection.url","jdbc:sybase:Tds:svc-xyz:4100/MYDB")
.setProperty("hibernate.connection.username","me")
.setProperty("hibernate.connection.password","******")
.setProperty("hibernate.connection.pool_size","2");
.setProperty("hibernate.current_session_context_class","thread");
// .setProperty("hibernate.cache.provider_class","org.hibernate.cache.NoCacheProvider")
//.setProperty("hibernate.transaction.manager_lookup_class","com.cmi2.platform.jms.xa.hibernate.CustomTransactionManager");
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = cfg.buildSessionFactory();
} catch (Throwable ex)
{
..
}
I have used all the above commented options but nothing works!!
Any poitners/help is much apprciated.
/Madhu