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
{{ message }}
Repository navigation
LazyConnectionDataSourceProxy does not work well with Hibernate's multi-tenancy by schema strategy #36527
In our application we defined an AbstractRoutingDataSource that routes to a read-only DataSource on read-only transactions, and a read-write DataSource otherwise:
publicclassRoutingDataSourceextendsAbstractRoutingDataSource {
@OverrideprotectedObjectdetermineCurrentLookupKey() {
if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
// returns read-only datasource
}
// return normal datasource
}
}
This DataSource is then wrapped in a LazyConnectionDataSourceProxy.
This works well as-is. However it does not work as expected when defining a tenant-by-schema strategy with Hibernate:
Reading this from a LazyConnectionDataSourceProxy perspective, you are effectively asking for delayed setSchema handling there which is a sensible feature request (plus corresponding setCatalog handling). I'll repurpose this issue for it, bringing this into 7.0.7.
changed the title [-]AbstractRoutingDataSource does not work well with Hibernate's multi-tenancy by schema strategy[/-][+]LazyConnectionDataSourceProxy does not work well with Hibernate's multi-tenancy by schema strategy[/+]on Mar 24, 2026
Activity
jhoeller commentedon Mar 24, 2026
Reading this from a
LazyConnectionDataSourceProxyperspective, you are effectively asking for delayedsetSchemahandling there which is a sensible feature request (plus correspondingsetCataloghandling). I'll repurpose this issue for it, bringing this into 7.0.7.Note that
LazyConnectionDataSourceProxyhas specific read-only DataSource support since 6.1.2: see https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.html#setReadOnlyDataSource(javax.sql.DataSource) - So you could replace your customRoutingDataSourcewith correspondingsetReadOnlyDataSourceconfiguration on theLazyConnectionDataSourceProxythat you have in place already.[-]AbstractRoutingDataSource does not work well with Hibernate's multi-tenancy by schema strategy[/-][+]LazyConnectionDataSourceProxy does not work well with Hibernate's multi-tenancy by schema strategy[/+]celcius112 commentedon Mar 24, 2026
@jhoeller Indeed ! But the
AbstractRoutingDataSourcelet me add a few logs in my example .Consistent handling of early setCatalog/setSchema/setHoldability calls
jhoeller commentedon Mar 24, 2026
This is pushed now and will be available in the upcoming 7.0.7 snapshot.
I'm backporting this to 6.2.18 as well, in combination with the related bug fix #36528.
Consistent handling of early setCatalog/setSchema/setHoldability calls