提交后可以回滚JTA事务吗? [英] Can I roll back a JTA transcation after I commit it?

查看:228
本文介绍了提交后可以回滚JTA事务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提交的JTA事务.提交后可以回滚吗?如果是,怎么办?我有以下情况.

I have a JTA transcation which I commit. Can I roll it back after I commit? If yes, how? I have following situation.

  1. 我有一个后端层,它更新了3个DB.我已经使用了JTA用户事务处理.如果任何数据库中的更新失败,则使用utx.rollback

  1. I have a backend layer which updated 3 DBs. I have used JTA user transcation for it. If update in any DB fails all updates to 3 DBs are rolled back using utx.rollback

现在,我在后端层之上有一个层,用于更新其他一些数据库.现在,我希望步骤1和步骤2都应该成功或都失败,所以我想在步骤2失败的情况下回退步骤1的JTA事务.

Now I have a layer on top of backend layer which updates some other DB. Now I want that step 1 and step 2 should both succeed or both fail, so I want to roll back JTA transcation of step 1 in case step 2 fails.

我很难将步骤2的代码放入1,因为我们正在使用一些现有的API在步骤2中更新数据库.

It's difficult for me to put code of step 2 into 1 as we are using some existing APIs to update DB in step 2.

推荐答案

我认为答案是,您不能使用JTA或其他RDBM来做类似的事情.

I think that the answer is that you cannot do anything like this using JTA, or other RDBMs.

事务已提交或已回滚.成功提交后,它们将无法回滚.

Transactions are either committed, or they are rolled back. Once successfully committed they cannot be rolled back.

唯一可能的解决方法"可能是尝试使用嵌套事务,然后回滚外部事务.但这可能行不通:

The only possible "out" might be to try and use nested transactions, and rollback the outer transaction. But that probably isn't going to work:

  • 并非所有JTA实现都支持嵌套事务.
  • 即使他们这样做,也不能保证外部事务将成功提交.这可能会使您承担其他"数据库的提交,并且JTA事务会回滚.

听起来您将不得不重新考虑您的持久性API.

It sound like you are going to have to rethink your persistence APIs.

这篇关于提交后可以回滚JTA事务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆