What is the 'best' way to do distributed transactions across multiple databases using Spring and Hibernate

后端 未结 5 1945
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 04:31

I have an application - more like a utility - that sits in a corner and updates two different databases periodically.

It is a little standalone app that has been bu

5条回答
  •  一个人的身影
    2020-11-28 05:24

    When you say "two different databases", do you mean different database servers, or two different schemas within the same DB server?

    If the former, then if you want full transactionality, then you need the XA transaction API, which provides full two-phase commit. But more importantly, you also need a transaction coordinator/monitor which manages transaction propagation between the different database systems. This is part of JavaEE spec, and a pretty rarefied part of it at that. The TX coordinator itself is a complex piece of software. Your application software (via Spring, if you so wish) talks to the coordinator.

    If, however, you just mean two databases within the same DB server, then vanilla JDBC transactions should work just fine, just perform your operations against both databases within a single transaction.

提交回复
热议问题