Can I roll back a JTA transcation after I commit it?
Asked Answered
M

4

2

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

  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

  2. 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.

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.

Mosstrooper answered 22/1, 2011 at 7:21 Comment(0)
E
3

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:

  • Not all JTA implementations support nested transactions.
  • Even if they did, there is no guarantee that the outer transaction will successfully commit. And that could leave you with the "other" DB committed and the JTA transaction rolled back.

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

Earleenearlene answered 22/1, 2011 at 7:45 Comment(0)
B
4

You can't rollback a transaction after it is committed.

Batter answered 22/1, 2011 at 7:46 Comment(1)
If you mark the transaction and use that to roll back. However, this would really depends on the situation.Orangewood
E
3

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:

  • Not all JTA implementations support nested transactions.
  • Even if they did, there is no guarantee that the outer transaction will successfully commit. And that could leave you with the "other" DB committed and the JTA transaction rolled back.

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

Earleenearlene answered 22/1, 2011 at 7:45 Comment(0)
J
1

As far as I know you cannot rollback a committed transaction. The underlying database will not support it. For instance oracle will not allow committed transaction to rollback.

Of course there is a way to return to previous state and the terminology is called "point in time recovery". Oracle's point in time recovery mechanism is called FlashBack.

http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28424/adfns_flashback.htm

This will allow you to revert your database state to a previous snapshot.

But the catch is, there is no JTA interface to perform this. (Infact it is outside the scope of Transaction Manager.)

The Best bet is to register savepoints in your transaction without committing and rolling back to the save point if one or more operation fails.

Jada answered 22/1, 2011 at 7:46 Comment(0)
I
0

You cannot rollback a committed transaction, whether it is an XA transaction or nonXA one.

To solve the problem you mentioned, one has to include ALL involved resources inside a single XA transaction.

If the above solution is not feasible for some reason, you can do this: a) Ask the first layer (of 3 DBs) to prepare. b) If outcome of (a) is OK, do a commit of the 4th DB. c) If outcome of (b) is OK, call the second phase commit over the 3 DBs.

HTH.

Thanks, Nitin

Independency answered 28/7, 2011 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.