hibernate/hibernate-orm · error · HibernateException
Credentials-based multitenancy not supported with read-only
Error message
Credentials-based multitenancy not supported with read-only replicas
What it means
Error "Credentials-based multitenancy not supported with read-only replicas" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/NonContextualJdbcConnectionAccess.java:52
Objects.requireNonNull( connectionProvider );
this.readOnly = readOnly;
this.listener = listener;
this.connectionProvider = connectionProvider;
this.session = session;
}
@Override
public Connection obtainConnection() throws SQLException {
final var eventMonitor = session.getEventMonitor();
final var connectionAcquisitionEvent = eventMonitor.beginJdbcConnectionAcquisitionEvent();
try {
listener.jdbcConnectionAcquisitionStart();
final Object tenantIdentifier = session.getTenantIdentifierValue();
if ( tenantIdentifier != null ) {
final var tenantCredentialsMapper = getTenantCredentialsMapper();
if ( tenantCredentialsMapper != null ) {
if ( readOnly ) {
throw new HibernateException( "Credentials-based multitenancy not supported with read-only replicas" );
}
return connectionProvider.getConnection(
tenantCredentialsMapper.user( tenantIdentifier ),
tenantCredentialsMapper.password( tenantIdentifier )
);
}
}
return readOnly
? connectionProvider.getReadOnlyConnection()
: connectionProvider.getConnection();
}
finally {
eventMonitor.completeJdbcConnectionAcquisitionEvent( connectionAcquisitionEvent, session, null );
listener.jdbcConnectionAcquisitionEnd();
}
}
private TenantCredentialsMapper<Object> getTenantCredentialsMapper() {View on GitHub (pinned to fad1729dce)
Solutions
- Do not combine credentials-based multitenancy with read-only replica routing; use one approach or configure separate connection providers.
When it happens
Trigger: Thrown when credentials-based multi-tenancy is combined with read-only replica configuration, which is unsupported.
Common situations: Typical situations: enabling both tenant-credentials connection access and read-only replica routing in the SessionFactory settings.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/78817bd4aa78aa4e.
Report an issue: GitHub.