Skip to content

Improve documentation to clarify coordination of multiple transaction managers #36684

Description

@quaff

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions