如何在JPA中处理两个war文件之间的事务管理(两个diff DB' s)

时间:2015-05-06 04:24:23

标签: distributed-transactions

我有两个PostgreSQL数据库。我将请求发送到一个数据库以执行一些DML操作,基于成功响应,我将向第二个数据库发送请求以执行一些DML操作。如果第二次操作失败,我该如何回滚第一次DB DML操作。

希望你们都明白我的问题。

1 个答案:

答案 0 :(得分:0)

标准回滚不适用,因为您需要语句1的结果并将其用于第二个语句。您需要在sql外的应用程序中执行此操作。

对于'人工回滚',您需要缓存由操作影响的行的原始值

该流程将在以下几行中发挥作用:

select * from table where the_Where; //statement 1

update db1.table set updates where the_Where;

--if success--
update db2.table set updates where another_Where;

--if failure--
update table set (data from statement 1) where the_Where;
相关问题