6

In my app, there are multiple steps where many commits to the database will be made sequentially through multiple methods. Example:

A -> B -> C
       -> D
           ->E
       -> F
  -> G

A calls B which calls C. Then B calls D. D calls E and so on. All of these methods have some database operations. As I understand from PROPAGATION_REQUIRED (declarative transaction management - the spring recommended way), if E completes successfully, the transaction (and operations in E will be committed). Now, due to some exception, F should lead to a rollback. I want to have everything rolled-back starting from what A did. Is this possible via Declarative Transaction management? Or should I use Programmatic Transaction Management?

Thank you.

App Work
  • 21,899
  • 5
  • 25
  • 38
TJ-
  • 14,085
  • 12
  • 59
  • 90

1 Answers1

7

First, "nested" transactions, in the sense that there are multiple running transactions depending on each other, is not supported, afaik.

Then, propagation=REQUIRED means that all methods with that propagation will:

  • start a new transaction if there is none exists
  • participate in an existing transaction if such exists.

This means that in your scenario, a failure in F would rollback the entire transaction (because it is a single transaction, started by A, and propagated to other methods)

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • I would have completely agreed with you until I read (somewhere - am unable to find where it was) that commit happens as soon as the method completes. I think I am wrong in the understanding here. When does the actual commit happen (we don't have to do explicitly do that. right?)? – TJ- Aug 23 '11 at 07:29
  • 1
    the commit happens when the method that started the transaction completes. It is `A` in this case – Bozho Aug 23 '11 at 07:42