Strange behaviour with @Transactional(propagation=Propagation.REQUIRES_NEW)
Spring transactions, by default, work by wrapping the Spring bean with a proxy which handles the transaction and the exceptions. When you call method2()
from method1()
, you're completely bypassing this proxy, so it can't start a new transaction, and you're effectively calling method2()
from the same transaction as the one opened by the call to method1()
.
On the contrary, when you call a method of another injected bean from method1()
, you're in fact calling a method on a transactional proxy. So if this alien method is marked with REQUIRES_NEW, a new transaction is started by the proxy, and you're able to catch the exception in method1()
and resume the outer transaction.
This is described in the documentation.