Announcement Announcement Module
No announcement yet.
Spring transactional support accross multiple databases Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring transactional support accross multiple databases


    In my project, I am having multiple databases. I need to provide transactional funtionality at a method which requires communication to both the databases.

    Now which Transactional manager should I configure? How to use it.

    Can someone provide the best way how to use apply transaction manager.


  • #2
    Can someone please provide a solution?

    Using Spring, we can define @Transactional annotation at the method level asking spring container to manage transaction. But correspondingly, we can define only 1 transaction manager.... Now if we have 2 databases, we need to transactional managers.

    Now 1 approach I can think of is using 2 different methods having @Transactional annotations defining different transaction managers to both. Will this work? If yes, I guess using this approach, we can achieve only 2 phase commit. Is this the best approach possible...???

    I also read somewhere that we can use Spring JTATransactionManager which provides approach using only 1 transactional manager... Is that true? if yes, can u please define how to acheive that?

    Please let me know for any better optimum approach. Please let me know.

    Thanks & Regards,


    • #3
      Hi Jubin,
      I actually wrote a post about getting started with XA transactions on my blog (

      But here is the gist: You do not need two transaction managers.What you do need is one JTATransactionManager like Bitronix or Atomikos etc., which - to be Bitronix specific - will allow you to setup PoolingDataSource(s) for your two databases.

      A bit of additional Spring config for the JTATransactionManager itself, so that your PoolingDataSources are getting used + your usual @EnableTransactionManagement and voila, finished. Then you are really good to go with @Transactional on service methods and nothing else, just like when using "normal" TransactionManagers.
      Last edited by marcobehler; May 2nd, 2014, 11:05 AM.


      • #4
        Thanks a lot Marcobehier.

        Its a nice and simple explaination.

        Please clarify me if I am wrong.

        PoolingDataSource is provided by BitronixTransactionManager. And we register both the databases with it. Once registered, we will wrap BitronixTransactionManager around Spring's JTATransactionManager. After enabling annotation based Tx Mgr, we need to simply use @Transaction annotation? Am I correct in my understanding?

        Thanks again.