Given two transaction managers tm1 and tm2, it's unclear that a transaction created by tm2 will or not participate in an existing transaction created by tm1. According to my investigation, the answer is yes if they share the same underlying resource, such as DataSourceTransactionManager for example:
@Test
public void test(@Autowired DataSource dataSource) {
DataSourceTransactionManager tm1 = new DataSourceTransactionManager(dataSource);
DataSourceTransactionManager tm2 = new DataSourceTransactionManager(dataSource);
TransactionTemplate tt1 = new TransactionTemplate(tm1);
TransactionTemplate tt2 = new TransactionTemplate(tm2);
tt1.executeWithoutResult(s1 -> {
assertThat(s1.isNewTransaction()).isTrue();
tt2.executeWithoutResult(s2 -> {
assertThat(s2.isNewTransaction()).isFalse();
});
});
}
It would be nice if the reference manual expounded on it and the Javadoc mentioned it.
Given two transaction managers
tm1andtm2, it's unclear that a transaction created bytm2will or not participate in an existing transaction created bytm1. According to my investigation, the answer is yes if they share the same underlying resource, such asDataSourceTransactionManagerfor example:It would be nice if the reference manual expounded on it and the Javadoc mentioned it.