Skip to content

Improve document to clarify coordination of multiple transaction managers #36684

@quaff

Description

@quaff

Given two transaction manager tm1 and tm2, It's unclear that transaction created by tm2 will or not participate in existing transaction created by tm1, according to my investigation, the answer is yes if they share same underlying resource, take 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 expand on it and the Javadoc mention it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions