1

I'm using schema based multi-tenancy providing implementations for both MultiTenantConnectionProvider & CurrentTenantIdentifierResolver. Trying to get a hibernate session for a single tenant fails with an NPE. Looking into hibernate's source code, it seems that JDBCServicesImpl initializes the connectionProvider to null in the else block

private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues) {
    final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configValues );

    if ( MultiTenancyStrategy.NONE == multiTenancyStrategy ) {
        connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
        return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
    }
    else {
        connectionProvider = null;
        final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService( MultiTenantConnectionProvider.class );
        return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
    }
}

Please find the test case for this here - http://pastebin.com/7Mt9wtHt and its stacktrace - http://pastebin.com/8ygAu7eh

Is there something basic I am missing out?

Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113

2 Answers2

2

Well, after looking at the source code for awhile now. Hibernate (as for now) does not support schema export. this is taken from their documentation.

Currently schema export will not really work with multi-tenancy. That may not change

So, in your case, the fix would be to remove this line

config.getProperties().put(AvailableSettings.HBM2DDL_AUTO, "validate");
kucing_terbang
  • 4,991
  • 2
  • 22
  • 28
0

I am also facing the same issue. When I googled, there is a bug posted for this in hibernate. Here is the link https://hibernate.atlassian.net/browse/HHH-7395