java - Spring transactions: Method with requires_new called from a method with requires -
i understand when commit happens , when rollback happens in case of nested transaction different isolation levels calling , called methods,
for example, have 2 spring services , i'm calling method2 of service2 method1 of service1.
method1 having required transaction scope , method2 having requires_new transaction scope shown in program below.
service1 { @transactional(propagation = propagation.required) method1() { for(int i=0; i<10; i++){ service2.method2(); } // more code takes time process } } service2 { @transactional(propagation = propagation.requires_new) method2() { //save information db // save object using jpa } }
now question is, understand requires_new start new transaction, commit on existing method2 or spring waits till method1 completed , commits?
i'm interested in @ point of time commit happens , row lock in db gets released persisted in method2.
note: here have placed both methods in different services spring can achieve nested transaction.
thanks in advance,
vali
when enter method2 of service2, transaction of service1 (say tx1) suspended , new transaction created service2 (say tx2). new transaction independent of previous transaction , wither commit or rollback independently.
tx2 commit/rollback when return service2 , after tx1 resume point suspended. result of tx2 (commit or rollback) not affect behavior of tx1.
please read spring documentation here. check section 16.5.7 more information transaction propagation.
Comments
Post a Comment