Support schema management tools with multi-tenancy (MultiTenantConnectionProvider)
Description
Attachments
Activity

Christian Beikov April 5, 2024 at 10:59 AM
Pretty sure this works now in ORM 6. If it doesn't, please let us know and submit a new test case against ORM 6.

Francisco Hansen February 7, 2018 at 11:01 AM
I've been able to use the "update" hbmddl.auto schema management setting. With the others, the exception is still thrown.
Steve Ebersole June 15, 2015 at 6:28 PM
As mentioned in the documentation, schema management tooling (export, update, validation) will not work currently with multi-tenancy. So first, this is not a bug as it is documented to not be available. The reason it does not work is that currently the contract for getting Connections in multi-tenant set ups does not provide a method for getting a Connection from all datasources nor a way to know all the tenants.

AmitS December 25, 2014 at 7:45 AM
I am facing the same issue. JdbcServicesImpl marking the connectionProvider as null. Is this a bug or some configuration is missing? Any updates?
Details
Details
Assignee
Reporter

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
*/
}