views:

1639

answers:

1

I have a DAO implementation that uses a HibernateTransactionManager for transaction management and the application has 2 session factories. I am getting an exception at the transactionManager.commit() line below. Does performing Hibernate operations within a transaction manager related to a different session factory cause problems?

TransactionStatus status = transactionManager.getTransaction(def);
try{
    doHibernateStuff1();  //Does Hibernate stuff with session
                          //factory related to Tx Manager
    doHibernateStuff2();  //Does Hibernate stuff with session 
                          //factory not related to Tx Manager
}
catch(DataAccessException){
 transactionManager.rollback(status);
}
transactionManager.commit(status); //Exception happens here.

The exception appears to be trying to perform the operations in doHibernateStuff2(); again in the txManager.commit().

If you want to suggest a kludge and/or proper way of dealing with this, I would appreciate it.

+2  A: 

Are you using XA drivers to connect to the two data sources involved in the transaction? Can't work otherwise.

duffymo
com.microsoft.jdbc.sqlserver.SQLServerDriver and net.sourceforge.jtds.jdbc.Driver; I'm not sure these are XA or not.
Brandon
No,net.sourceforge.jtds.jdbcx.JtdsDataSource is the jTDS XA driver class; see http://msdn.microsoft.com/en-us/library/aa342335(SQL.90).aspx for Microsoft's XA driver. (You have to install DLL for the latter.)
duffymo
Why are you using both the jTDS and Microsoft drivers? Why not just one or the other?
duffymo
This was work that had been previously but I don't believe there is a reason for this.
Brandon
jTDS is pure type IV; no DLLs needed for XA driver.
duffymo