Skip to content

Commit ff2c19c

Browse files
won-seoopclaude
andcommitted
GH-36684: Document transaction coordination between managers sharing a DataSource
Two DataSourceTransactionManager instances configured with the same DataSource object participate in the same JDBC connection and physical transaction. This follows from both managers using the same TransactionSynchronizationManager key (the DataSource instance), so the second getTransaction() call detects and joins the existing connection. This shared-DataSource behavior was previously undocumented, leading to confusion about whether multiple transaction managers can truly coordinate. Add a Javadoc paragraph to DataSourceTransactionManager explaining the behavior and when to prefer separate DataSource instances or JTA. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5e5d299 commit ff2c19c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@
106106
* is available as an extended subclass which includes commit/rollback exception
107107
* translation, aligned with {@link org.springframework.jdbc.core.JdbcTemplate}.</b>
108108
*
109+
* <p><b>Transaction manager coordination:</b> When two {@code DataSourceTransactionManager}
110+
* instances are configured with the <em>same</em> {@code DataSource} object, the second
111+
* manager's {@code getTransaction()} will detect and participate in the connection already
112+
* bound to the thread by the first, because both managers use the same
113+
* {@link TransactionSynchronizationManager} key (the {@code DataSource} instance).
114+
* As a result, nested {@code TransactionTemplate}/{@code @Transactional} calls that use
115+
* different manager beans but the same underlying {@code DataSource} share the same JDBC
116+
* connection and physical transaction. This is generally the desired behavior for such
117+
* setups. If separate, independent transactions are required, configure each manager with
118+
* a distinct {@code DataSource} (or use JTA).
119+
*
109120
* @author Juergen Hoeller
110121
* @since 02.05.2003
111122
* @see #setNestedTransactionAllowed

0 commit comments

Comments
 (0)