Skip to content

spr-16876-transactionsynchronizationmanager-not-returning-correct-values-in-impl #34777

@codetoddlers

Description

@codetoddlers

https://stackoverflow.com/questions/76136715/spr-16876-transactionsynchronizationmanager-not-returning-correct-values-in-impl

In the AbstractPlatformTransactionManager.java, the logic to start new transaction is written inside the startTransaction() as below

private TransactionStatus startTransaction(TransactionDefinition definition, Object transaction,
boolean debugEnabled, @nullable SuspendedResourcesHolder suspendedResources) {

boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
DefaultTransactionStatus status = newTransactionStatus(
definition, transaction, true, newSynchronization, debugEnabled, suspendedResources);
doBegin(transaction, definition); //Transaction is getting built here and connection is getting acquired here based on RoutingDataSource.determineCurrentLookupKey()
prepareSynchronization(status, definition); //Transaction is getting synchronized after the connection is built
return status;

}
As you can see in the above code transaction is getting synchronized after connection is acquired. So RoutingDataSource.determineCurrentLookupKey() will not be called after prepareSynchronization(status, definition).

Will there be a fix to synchronize the transaction before the connection is getting acquired ? Or is this the default functionality?

I could not track the issue(https://jira.spring.io/browse/SPR-16876?redirect=false) in the github as it might have been lost or to be not found.
Even 6.2.x still has this behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions