-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Inconsistent Transaction and TransactionSynchronizationManager Attributes with Nested Transactions in Multi-Transaction Manager Environment #35039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
teahyuk
wants to merge
2
commits into
spring-projects:main
from
teahyuk:fix-supportsPropagation-unsync-another-transaction-manager
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...t supports Signed-off-by: 정태혁 <jtaeh57@gmail.com>
Signed-off-by: 정태혁 <jtaeh57@gmail.com>
@spring-projects-issues
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged or decided on
label
Jun 12, 2025
@sbrannen
sbrannen
added
the
in: data
Issues in data modules (jdbc, orm, oxm, tx)
label
Jun 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi !
situation
In a multi-transaction manager environment, when
@Transactional
annotations from different transaction managers are nested, the attributes of TransactionSynchronizationManager do not align with the current transaction if the inner@Transactional
method has a propagation level ofSUPPORTS
,NOT_SUPPORTS
, orNEVER
.Specifically, TransactionSynchronizationManager inherits the attributes (e.g., readOnly status) of the outer/parent's
other transaction manager
, rather than reflecting the characteristics of the "empty" or "non-participating" transaction created by the inner@Transactional
method under these propagation settings. This leads to a mismatch between the expected transaction state and the state reported by TransactionSynchronizationManager.Steps to Reproduce
Consider the following simplified example:
Expected Behavior
When transactionSecond() is invoked,
TransactionSynchronizationManager.isCurrentTransactionReadOnly()
should accurately reflect the characteristics of the current transaction context established by manager2's @transactional, irrespective of any parent transaction's attributes.This is especially critical when the parent transaction originates from a different transaction manager. While it might seem that
PROPAGATION_SUPPORTS
,PROPAGATION_NOT_SUPPORTED
, orPROPAGATION_NEVER
shouldn't be affected as they don't create a new transaction,@Transactional
attributes like readOnly can be set regardless of whether a physical transaction is actually active. Therefore, these attributes should be applied and reflected independently.Indeed, if
@Transactional(transactionManager = "manager2", readOnly = false, propagation = Propagation.SUPPORTS)
were to execute without a parent transaction,TransactionSynchronizationManager.isCurrentTransactionReadOnly()
would correctly return false. This demonstrates that@Transactional
attributes should be precisely reflected, regardless of the presence of other transaction managers.Therefore, whether
transactionFirst()
is invoked ortransactionSecond()
is called directly,assert TransactionSynchronizationManager.isCurrentTransactionReadOnly()
should not throw an exception.Actual Behavior
However, when
transactionFirst()
is invoked, anAssertionError
is thrown whentransactionSecond()
is called. Conversely, iftransactionSecond()
is invoked directly, noAssertionError
occurs.Proposed Changes
In AbstractPlatformTransactionManager.getTransaction(Definition), we've added suspend logic at the very end of the method. This ensures that when a transaction context is established with propagations like
PROPAGATION_SUPPORTS
,PROPAGATION_NOT_SUPPORTED
, orPROPAGATION_NEVER
, any previously active transaction (potentially from another TransactionManager) is correctly suspended. This guarantees that TransactionSynchronizationManager accurately reflects the characteristics of the current transaction context, preventing inconsistencies in readOnly status and other attributes.