You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading Spring Boot from 3.2.7 to 3.3.1 our multi-datasource based on the AbstractRoutingDataSource stopped working. We have a test that tests different @Transactional - combinations.
I did read a lot about the LazyConnectionDataSourceProxy in issues like #15480, but nothing really worked:
Use LazyConnectionDataSourceProxy as my primary datasource with the target / readonly datasource feature
Wrapping our AbstractRoutingDataSource in LazyConnectionDataSourceProxy
Thanks for the sample. The change in behaviour is due to Hibernate which Spring Boot 3.3.x upgrades to 6.5.x. If I run the tests with Spring Boot 3.3.1 and Hibernate downgraded to 6.4.9.Final they all pass.
I'm not sure that a fully understand the purpose of the tests, but they appear to be relying on some side-effects of Hibernate's behavior despite not actually using JPA. Specifically, they seem to be relying up Hibernate calling getConnection() on the DataSource. I would guess that some optimisations in Hibernate 6.5.x mean that it no longer gets a connection so eagerly which results in connectionReadOnlyCaptor not capturing anything.
You can see similar failures with Spring Boot 3.2.7 if you change the tests from @DataJpaTest to @JdbcTest. Doing so takes Hibernate out of the picture and means that getConnection() is never called on the DataSource. As far as I can tell, you need to rework your tests to avoid relying upon a side-effect of how Hibernate behaves.
To cause seems to be a change in org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor where the commit() method now checks isPhysicallyConnected() which returns false.
Adding a simple entityManager.createQuery("select 1").getResultList(); to all inner transactions fixes nearly all tests, because it forces a connection acquisition (took it from the test from the linked commit) and hence a call for dataSource.getConnection().
Description
After upgrading Spring Boot from
3.2.7
to3.3.1
our multi-datasource based on the AbstractRoutingDataSource stopped working. We have a test that tests different@Transactional
- combinations.I did read a lot about the
LazyConnectionDataSourceProxy
in issues like #15480, but nothing really worked:LazyConnectionDataSourceProxy
as my primary datasource with the target / readonly datasource featureAbstractRoutingDataSource
inLazyConnectionDataSourceProxy
Versions
OS: macOS 14.5
Java: 17
Spring Boot:
How to reproduce the issue
Repository: https://github.com/open-source-issues/spring-multi-datasource
Command: https://github.com/open-source-issues/spring-multi-datasource/blob/main/README.md
The text was updated successfully, but these errors were encountered: