-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate4Beta1: NPE when using C3PO within persistence.xml
PostPosted: Thu Jun 16, 2011 9:40 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
As soon I call
javax.persistence.Persistence.createEntityManagerFactory("bclayer");

I get following NPE:

Code:
Caused by: java.lang.NullPointerException
   at org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:75)
   at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:227)
   at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:113)
   at org.hibernate.service.internal.BasicServiceRegistryImpl.configureService(BasicServiceRegistryImpl.java:80)
   at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:143)
   at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:118)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:68)
   at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2251)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2247)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1718)
   at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:77)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:894)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:879)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)



The problem is that C3P0ConnectionProvider#getConnection() reads an uninizialized datasource variable 'ds':

Code:
/**
    * {@inheritDoc}
    */
   public Connection getConnection() throws SQLException {
      final Connection c = ds.getConnection(); // C3P0ConnectionProvider.java:75   Datasource ds is not initalized
      if ( isolation != null ) {
         c.setTransactionIsolation( isolation.intValue() );
      }
      if ( c.getAutoCommit() != autocommit ) {
         c.setAutoCommit( autocommit );
      }
      return c;
   }



That datasource variable 'ds' get defined in method C3P0ConnectionProvider#configure()
but this method get not called at all!
What im doing wrong?

This is my persistence.xml:

Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"  version="2.0">
<persistence-unit name="bclayer">
   <properties>

    <property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"/>
    <property name="hibernate.c3p0.min_size"         value="5"/>   
    <property name="hibernate.c3p0.max_size"         value="800"/>   
    <property name="hibernate.c3p0.max_statements"   value="10000"/>   
    <property name="hibernate.c3p0.timeout"          value="3600"/>   
    <property name="hibernate.c3p0.idle_test_period" value="3000"/> 
     
<!-- JDBC-driver -->
    <property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
    <property name="hibernate.connection.url" value="jdbc:sqlserver://pbz:1433;databasename=TestServer3"/>
    <property name="hibernate.connection.username" value="sa"/>
    <property name="hibernate.connection.password" value="123"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
   
    ...
   
   </properties>
</persistence-unit>
</persistence>




Any hint what I'm doing wrong?


Top
 Profile  
 
 Post subject: Re: Hibernate4Beta1: NPE when using C3PO within persistence.xml
PostPosted: Thu Jun 16, 2011 10:05 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
The method C3P0ConnectionProvider#configure() isn't called because C3P0ConnectionProvider does not implement org.hibernate.service.spi.Configurable, see code below:

BasicServiceRegistryImpl.java:

Code:
@Override
   protected <T extends Service> void configureService(T service) {
      applyInjections( service );

      if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
         ( (ServiceRegistryAwareService) service ).injectServices( this );
      }

      if ( Configurable.class.isInstance( service ) ) {
         ( (Configurable) service ).configure( configurationValues );
      }
   }


org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider.java:

Code:
public class C3P0ConnectionProvider implements ConnectionProvider {


Seems to me like a bug.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.