-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 4.1.2.Final NPE in LogicalConnectionImpl
PostPosted: Mon Apr 30, 2012 10:20 am 
Newbie

Joined: Mon Apr 30, 2012 7:10 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Hibernate 4.1.2.Final NPE in LogicalConnectionImpl
PostPosted: Tue May 08, 2012 6:40 am 
Newbie

Joined: Fri Mar 02, 2007 4:32 am
Posts: 5
Location: Munich, Germany
Hi,

thank you for your analysis. I stumbled over the very same regression and created a ticket in hibernate JIRA https://hibernate.onjira.com/browse/HHH ... ntId=46561 describing a workaround (Setting Release mode to AFTER_TRANSACTION in two places).

Hope that helps.

Christian

_________________
Christian Kalkhoff
JavaEE Developer
Linux Administrator
http://www.kalkhoff.net


Top
 Profile  
 
 Post subject: Re: Hibernate 4.1.2.Final NPE in LogicalConnectionImpl
PostPosted: Tue May 08, 2012 7:47 am 
Newbie

Joined: Mon Apr 30, 2012 7:10 am
Posts: 2
Thanks Christian. I thought I was alone :)

I have also updated the JIRA.

Regards,

Jegan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.