I would like to understand when exactly commit happens and when exactly rollback happens in case of nested transaction with different isolation levels to calling and called methods,
For example, I have two spring services and i'm calling method2 of service2 from method1 of service1.
Method1 is having REQUIRED transaction scope and Method2 is having REQUIRES_NEW transaction scope as shown in the program below.
Service1 {
@Transactional(propagation = Propagation.REQUIRED)
method1()
{
for(int i=0; i<10; i++){
service2.method2();
}
// Some more code which takes some time to process
}
}
Service2 {
@Transactional(propagation = Propagation.REQUIRES_NEW)
method2()
{
//Save some information to DB
// Save an object using JPA
}
}
Now my question is, As i understand REQUIRES_NEW will start a new transaction, But will it commit immediately on existing method2 or will the spring waits till method1 is completed and then commits?
I'm interested in at what point of time commit happens and row lock in DB gets released which is persisted in method2.
Note: Here i have placed both methods in different services so that spring can achieve nested transaction.
Thanks in Advance,
Vali