views:

36

answers:

2

Hi,

If I have the transactionable methods A,B,C and A calls B,C ; then, C throws exception that is not caught inside A.

My question is if B will be rolled back or not?

Please note that nested transactions are disabled by default so A, B, C are all transactionable by themselves.

Thanks

A: 

Yes.

If A, B, and C are all @Transactional methods, and A calls B and C, Spring will manage the transactional nature of all three using a single transaction. In other words, the invocation of A, B, and C will in effect share a single transaction. If C throws an exception, the single transaction used by A, B, and C would be rolled back.

James Earl Douglas
A: 

Note that Spring by default only rolls back transactions when a RuntimeException (or a subclass) is thrown outside the transaction boundaries (i.e. when the exception is not caught by your transactional method).

A checked exception will NOT cause Spring to mark the transaction for rollback unless you specify it explicitly.

Eran Harel