HibernateTransactionManager (Spring) with multiple session entries

I have a DAO implementation that uses HibernateTransactionManager to manage transactions and my application has 2 session factories. I am getting an exception on the transactionManager.commit () line below. Do Hibernate operations in the transaction manager, associated with another factory session, get the problem?

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 seems to be trying to perform operations at doHibernateStuff2();

again at txManager.commit()

.

If you would like to suggest a kludge and / or a correct way to handle this, I would appreciate it.

+1


source to share


2 answers


Are you using XA drivers to connect to the two data sources involved in a transaction? It cannot work otherwise.



+2


source


I know this is an old question, but I ran into a similar problem. I believe Brandon has 2 session factories for different datasources and uses HibernateTransactionManager . And I think using such a manager is a problem. From what I've read, the HibernateTransactionManager cannot handle two different session factories. Instead, he must use another manager, such as the JTA transaction manager. But only if he needs access to both data sources in one transaction. Otherwise, the solution is to use an additional manager for each factory session as mentioned in the link below:



similar problem

0


source







All Articles