简体   繁体   中英

How to make sure multiple DBs are transacted with a single transaction manager in spring?

I am using mulitple transaction managers (HibernateTransactionManager) one for each database.

During one code flow I believe I start/finish multiple transactions for each database.

I want to make sure all database transactions are part of single transaction. How can I acheive this?

One of the post here suggest to use JTATransaction manager, should I use that in combination with already using Hibernate?

Although I think In case of execption during any phase of application, all the transactions will be rolled back.

I am using Spring 4.1.* and hibernate 3.6.* and NOT using any webcontainer.

It is years since I worked with Hibernate, so apologies in advance if any of this is misleading.

  • You need JTA transactions. Your DataSources need to support JTA.
  • If you are running in a web container like Weblogic or Websphere, then creating a JTA transaction is easy. I don't think Tomcat will suffice here. From a command line program, I have not found an answer.
  • If you have full control over the three databases, you should be fine. But be aware that rollback over systems that involve web services can be patchy or require non-standard protocols (eg Weblogic only supports SOAP JTA over t3 protocol)

If you get results, please share as the amount of good advice in this area is minimal.

(edit)Just noticed you clearly stated that you are not using a web container. If you come across a solution for a command line program, there are lots of us that would like to know. Building JUnit tests for distributed transactions is something I want to do, but have never found how to generate the JTA transaction object (/edit>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM