Here is an example where I am using JdbcTemplate. My question doMultipleCalls()
fail at step 3 due to runTimeException, will everything gets rolledback.
I have @Transactional
annotation only to doMultipleCalls
but not to others. Is the same transaction session shared across all of them?. If not how to pass same transaction session across?
@Component
public class MyRespository {
@Autowired
JdbcTemplate template
@Transactional
public void doMutlipleCalls() {
callUpdate(); //1
callInsert(); //2
callDelete(); //3
}
callUpdate() {
template.query(...)
}
callInsert() {
template.query(...)
}
callDelete() {
template.query(..)
}
}
Is the same transaction session shared across all of them?
Yes. The transaction is begun prior to entering the doMultipleCalls()
method and is completed once it returns.