I know when a transactional method is called from inside the same class it wouldn't be run in a transaction. Spring creates a proxy for transactional methods and wraps them in a try-catch block and rolls back if an exception occurs. Consider the following scenario:
@Transactional
public void saveAB(A a, B b)
{
saveA(a);
saveB(b);
}
@Transactional
public void saveA(A a)
{
dao.saveA(a);
}
@Transactional
public void saveB(B b)
{
dao.saveB(b);
}
Assume saveAB is called from another object and an exception occurred in saveB, so saveA completed successfully but saveB did not. To my knowledge even though saveA and saveB are not transactional (because they are called from the same object), since saveAB is transactional it should still roll back.
What I don't understand is why do people say self invocation breaks transaction? As long as the caller method is transactional shouldn't everything work as expected? Is there anything I'm missing here?