Skip to content
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

IsolationLevelDataSourceRouter does not work with DataSourceTransactionManager [SPR-15121] #19688

Open
spring-projects-issues opened this issue Jan 10, 2017 · 5 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 10, 2017

springrain opened SPR-15121 and commented

IsolationLevelDataSourceRouter.determineCurrentLookupKey returns the result was null, since AbstractPlatformTransactionManager.getTransaction (TransactionDefinition definition) before calling doBegin(Object transaction, TransactionDefinition definition), setCurrentTransactionIsolationLevel(Integer isolationLevel) is not set, but get a connection, it's bug.


Affects: 4.3.4

Referenced from: pull request #1291

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 10, 2017

Juergen Hoeller commented

IsolationLevelDataSourceRouter is primarily intended for JTA scenarios where Connection lookups only happen after transaction begin. With DataSourceTransactionManager, the isolation level is applied to the retrieved Connection directly, so it is not really designed to interact with such DataSource-specific isolation setup.

Are you trying to optimize the switching overhead there? Why are you using IsolationLevelDataSourceRouter to begin with?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 10, 2017

springrain commented

I used to read and write the database separation,I don't have to use JTA

<bean id="dataSource" class="org.springframework.jdbc.datasource.lookup.IsolationLevelDataSourceRouter">
<property name="targetDataSources">
<map>
<entry key="ISOLATION_READ_UNCOMMITTED" value-ref="dataSourceWrite"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSourceRead"/>
</bean>

@andrei-ivanov
Copy link

@andrei-ivanov andrei-ivanov commented Sep 17, 2020

I've hit a similar issue, where I'm trying to use the readOnly status of the transaction to determine which dataSource to use, just to see that AbstractPlatformTransactionManager#prepareSynchronization is invoked just after doBegin, which obtains the connection (using a JpaTransactionManager) 😥

@andrei-ivanov
Copy link

@andrei-ivanov andrei-ivanov commented Sep 18, 2020

is there any chance that moving the prepareSynchronization call before doBegin might work?

@andrei-ivanov
Copy link

@andrei-ivanov andrei-ivanov commented Sep 22, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.