Skip to content

Improve transaction state detection logic#1144

Open
wanggang1111111 wants to merge 6 commits intomybatis:masterfrom
wanggang1111111:master
Open

Improve transaction state detection logic#1144
wanggang1111111 wants to merge 6 commits intomybatis:masterfrom
wanggang1111111:master

Conversation

@wanggang1111111
Copy link
Copy Markdown

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.

@hazendaz
Copy link
Copy Markdown
Member

@wanggang1111111 Please add back the line you deleted and remove the liekly 'vim' command you stuck in that java doc.

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