-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate, c3p0 and "No JDBC driver class..."
PostPosted: Mon Sep 27, 2010 9:55 am 
Newbie

Joined: Mon Sep 27, 2010 9:16 am
Posts: 2
Hello, community!

I use in my project:
  • hibernate-code 3.5.1-Final
  • hibernate-entitymanager 3.5.1-Final
  • hibernate-c3p0 3.5.1-Final

And I have a problem... :-)

When I was tried to build EJB factory via Persistences.createEntityManagerFactory(...) I've got next exception:
Quote:
10/09/27 17:08:34 INFO connection.ConnectionProviderFactory: Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider
10/09/27 17:08:34 INFO connection.C3P0ConnectionProvider: C3P0 using driver: null at URL: jdbc:mysql://127.0.0.1:3306/vio
10/09/27 17:08:34 INFO connection.C3P0ConnectionProvider: Connection properties: {useUnicode=true, user=root, password=****, autocommit=true, characterEncoding=UTF-8, release_mode=auto}
10/09/27 17:08:34 INFO connection.C3P0ConnectionProvider: autocommit mode: true
10/09/27 17:08:34 WARN connection.C3P0ConnectionProvider: No JDBC Driver class was specified by property hibernate.connection.driver_class
10/09/27 17:08:34 INFO log.MLog: MLog clients using log4j logging.
10/09/27 17:08:34 ERROR connection.C3P0ConnectionProvider: could not instantiate C3P0 connection pool
//...
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:314)
//...


After some googling about I'd read that c3p0 crashes with NPE if it's config contains some null values, but I had check each of them and their was initialized and contains value.
Then I decided that c3p0 don't get some overrided options of EJB factory...

This is a code of it's construction process:
Code:
public Map<String, Object> createConfigObject() throws ConfigException {
        IConfig databaseConfigNode = Registry.getConfig().get("database");

        Map<String, Object> override = new HashMap<String, Object>();
        override.put("hibernate.connection.driver_class", databaseConfigNode.get("adapter") );
        override.put("hibernate.connection.url", databaseConfigNode.get("uri").value() );
        override.put("hibernate.connection.username", databaseConfigNode.get("user").value() );
        override.put("hibernate.connection.password", databaseConfigNode.get("password").value() );
        override.put("hibernate.connection.useUnicode", databaseConfigNode.get("useUTF8").value() );
        override.put("hibernate.connection.characterEncoding", databaseConfigNode.get("charset").value() );

        return override;
}

public EntityManagerFactory createEJBFactory( boolean rebuildSchema ) throws ConfigException, SQLException, ProviderException {
        Map<String, Object> configMap = this.createConfigObject();
        configMap.put("hibernate.hbm2ddl.auto", rebuildSchema ? "create-drop" : "update");

        return Persistence.createEntityManagerFactory( Registry.getConfig().get("database").get("persistenceUnit").value(), configMap );
    }


But my assumptions not confirmed because I tried to put hibernate.connection.driver_class to persistence.xml, and c3p0 see it too...

Here 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="Persister">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
   
    <!-- classes declarations here... -->

    <properties>
        <property name="hibernate.hbm2ddl.throwExceptions" value="true" />
        <!-- SQL dialect -->
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <!-- Enable HibernateManagersFactory's automatic session context management -->
        <property name="hibernate.current_session_context_class" value="thread"/>
        <!-- Disable the second-level cache -->
        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
        <!-- Echo all executed SQL to stdout -->
        <property name="hibernate.show_sql" value="false"/>
        <!-- Drop and re-create the database schema on startup -->
       
        <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory" />
       
        <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>

        <property name="hibernate.c3p0.max_size" value="20"/>
        <property name="hibernate.c3p0.max_statements" value="0"/>
        <property name="hibernate.c3p0.min_size" value="5"/>
        <property name="hibernate.c3p0.idle_test_period" value="14400"/>
        <property name="hibernate.c3p0.timeout" value="25200" />
        <property name="hibernate.c3p0.preferredTestQuery" value="select 1;"/>
        <property name="hibernate.c3p0.acquireIncrement" value="2"/>

         <!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file -->
         <!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
    </properties>

  </persistence-unit>
</persistence>


It needs to say that few time ago all works fine...

Can anybody helps me?)


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

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.