Take the 2-minute tour ×

Here's the scenario and by the way, I'm looking for a Java-centric answer.

  1. Client code calls REST Service A (POST) from Provider Application #1.
  2. Client code directly updates an internal database using JDBC.
  3. Client code calls REST Service B (POST) from Provider Application #2.
  4. Steps 1 to 3 need to occur in a distributed transaction with two phase commit support i.e. if Step 2's database update fails, then we want to undo Step 1's POST. If Step 3's POST fails, we want to undo Step 1's POST and Step 2's database update.

Is there a way we can accomplish this using JTA without writing our own compensation code (to undo Step 1 and 2)?

share|improve this question
Most of this is possible using the Java Transaction API with XA Resources. However the hard part involves undoing a POST request, you can't really do that unless the providers application has some nonstandard logic for it. –  Devin M Mar 20 '12 at 18:24
add comment

1 Answer

You can not coordinate or manage a distributed transaction unless each of the participants supports two phase commit independently.

So in this case - if your REST Services supported two methods equivalent to two phases of the transaction - you could have implemented a transaction manager in your client.

share|improve this answer
add comment

Your Answer


