Skip to content

Conversation

@wanggang1111111
Copy link

When DataSourceUtils.getConnection(this.dataSource) creates a new connection,
this connection is automatically registered with Spring's TransactionSynchronizationManager.
Therefore, DataSourceUtils.isConnectionTransactional() returns true,
but in reality, this connection is newly created and should not be considered as a Spring-managed transactional connection.

Use TransactionSynchronizationManager.isActualTransactionActive() to check if there is an active Spring transaction.
Only when an active transaction exists should the connection be considered as a Spring-managed transactional connection.

This approach correctly distinguishes between newly created connections and genuine Spring-managed transactional connections.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants