If you have provided your own MultiTenantConnectionProvider using the database based Multi-tenant strategy this provider is not used by JdbcServicesImpl and the connection provider is not initialized. Please see attached unit test.
This problem prevents you from providing your own MultiTenantConnectionProvider.
/**
- Sequence of events
- 1.
- buildJdbcConnectionAccess - JdbcServicesImpl
-
if ( MultiTenancyStrategy.NONE == multiTenancyStrategy ) {
connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
}
else {
//HITS THIS BLOCK IN JdbcServicesImpl intializing service, connectionProvder is set to null
connectionProvider = null;
final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService( MultiTenantConnectionProvider.class );
return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
}
2. SessionFactory Impl validates schema
if ( settings.isAutoValidateSchema() ) {
new SchemaValidator( serviceRegistry, cfg ).validate();
}
3. SuppliedConnectionProviderConnectionHelper constructor passed connection provider from JdbcServicesImpl which is null
4. SuppliedConnectionProviderConnectionHelper prepare calls
public void prepare(boolean needsAutoCommit) throws SQLException {
connection = provider.getConnection(); THROWS NPE
*/
}
|