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?