Hi All,
I am trying to do a prototype for Multi-Tenancy with Hibernate. I am using Hibernate-4.1.2-Final with Spring-3.1.
I am facing the below NullPointerException when I try to launch my application.
Code:
java.lang.NullPointerException
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.determineConnectionReleaseMode(LogicalConnectionImpl.java:119)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.<init>(LogicalConnectionImpl.java:100)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.<init>(LogicalConnectionImpl.java:82)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.<init>(JdbcCoordinatorImpl.java:75)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.<init>(TransactionCoordinatorImpl.java:87)
at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:245)
at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1831)
at org.hibernate.context.internal.JTASessionContext.buildOrObtainSession(JTASessionContext.java:153)
at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:109)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1039)
When I analyzed, I found out that the below code in JdbcServiceImpl.java sets the connection provider to null.
Code:
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 );
}
}
In my case, the strategy is SCHEMA and hence, connectionProvider is set to null. Later at some point, the below code in LogicalConnectionImpl.java tries to find out the connection release mode and my connection release mode is AFTER_STATEMENT.
Code:
private static ConnectionReleaseMode determineConnectionReleaseMode(
JdbcServices jdbcServices,
boolean isUserSuppliedConnection,
ConnectionReleaseMode connectionReleaseMode) {
if ( isUserSuppliedConnection ) {
return ConnectionReleaseMode.ON_CLOSE;
}
else if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT &&
! jdbcServices.getConnectionProvider().supportsAggressiveRelease() ) {
LOG.debug( "Connection provider reports to not support aggressive release; overriding" );
return ConnectionReleaseMode.AFTER_TRANSACTION;
}
else {
return connectionReleaseMode;
}
}
jdbcServices.getConnectionProvider() returns null and hence the null pointer exception is thrown. Is this an issue? I am not sure if I am doing something wrong. I followed the steps specified in the documentation. I could see the call comes to my MultiTenantConnectionProvider and Hibernate is able to connect to my db and get the meta data information. (Code in JdbcServicesImpl.configure method).
Please let me know if I am missing something. Thanks for your time.
Regards,
Jegan