Can I roll back a JTA transaction after I complete it?

I have a JTA transaction that I am committing. Can I get it back after committing? If so, how? I have the following situation.

  • I have a backend layer that updated 3 DB. I used JTA translation for this. If the update in any database fails, all 3 DB updates will be rolled back using utx.rollback

  • Now I have a layer on top of the backend layer that updates some other databases. Now I want this step 1 and step 2 to succeed or both fail, so I want to cancel the JTA transfer in step 1 if step 2 fails.

I find it difficult to set the code of step 2 to 1, since we use some existing APIs to update the database in step 2.

0
source share
4 answers

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

Transactions are either completed or rolled back. After successful execution, they cannot be thrown back.

The only possible "way out" may be an attempt to use nested transactions and rollback an external transaction. But this probably won't work:

  • Not all JTA implementations support nested transactions.
  • Even if they did, there is no guarantee that the external transaction will be completed successfully. And this may leave you with a "different" database, and the JTA transaction rolled back.

It sounds like you have to rethink your persistence APIs.

+2
source

You cannot cancel a transaction after it is completed.

+3
source

As far as I know, you cannot cancel a committed transaction. The underlying database does not support it. For example, oracle will not allow transaction rollback.

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

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

This will allow you to return the database state to the previous snapshot.

But the trick is there is no JTA interface to accomplish this. (Infact goes beyond Transaction Manager.)

It is best to register savepoints in a transaction without committing or rolling back to the savepoint if one or more operations do not work.

+1
source

You cannot cancel a committed transaction, be it an XA or nonXA transaction.

To solve the problem you mentioned, you need to enable ALL involved resources within the same XA transaction.

If the indicated solution is impossible for some reason, you can do this: a) Ask to prepare the first layer (from 3 databases). b) If the result (a) is in order, fix the 4th DB. c) If result (b) is OK, call up the second phase lock after 3 DB.

NTN.

Thanks Nitin

0
source

Source: https://habr.com/ru/post/1383594/


All Articles