-->
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.  [ 4 posts ] 
Author Message
 Post subject: c3p0 doesn't work for me?!
PostPosted: Mon Nov 10, 2008 7:29 am 
Newbie

Joined: Fri Nov 07, 2008 1:57 pm
Posts: 8
I'm trying to get c3p0 work. I defined c3p0 properties in hibernate.cfg.xml file as stated in Hibernate tutorial and "Java Persistence with Hibernate" book, and added c3p0 jar file to classpath. When I run my program, hibernate prints this to the console:

[...]
INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
[...]

which means it doesn't use c3p0, right? Instead, it is using built-in connection pool, which should be disabled with c3p0.max_size property according to Hibernate documentation. Documentation also says: "Just replace the hibernate.connection.pool_size property with connection pool specific settings. This will turn off Hibernate's internal pool."

Functionally, everything works without pool. But I want that third-party connection pool working, for future use. Am I missing something in configuration?

Hibernate version: 3.3.1

Mapping documents:

hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

   <hibernate-configuration>
      
      <session-factory>   

      
         <!-- properties -->
         <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
         <property name="connection.url">jdbc:mysql://localhost:3306/DVDklub</property>
         <property name="connection.username">...</property>
         <property name="connection.password">...</property>
         <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
         <property name="show_sql">true</property>
         <property name="current_session_context_class">thread</property>
          
         <!--  c3p0 -->
         <property name="c3p0.max_size">100</property>
         <property name="c3p0.max_statements">50</property>
         <property name="c3p0.min_size">10</property>
         <property name="c3p0.timeout">100</property>   
         
         
         <!-- mapping files -->
          
         ...

          
       </session-factory>
   
   </hibernate-configuration>



HibernateUtil.java:

Code:
import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}


Application code:

Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
      
// for example
Person person = new Person();
person.setName("John Smith");

session.save(person);
      
session.getTransaction().commit();


Name and version of the database you are using: MySQL Community Server 5.0.67


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2008 7:59 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Try adding:

Code:
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2008 11:04 am 
Newbie

Joined: Fri Nov 07, 2008 1:57 pm
Posts: 8
Thanks. That made it work.

Just wondering again, why stuff like this isn't clearly documented in Hibernate docs ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 10:58 am 
Newbie

Joined: Tue Nov 01, 2005 2:00 pm
Posts: 10
Thanks! This worked!
I think that this is a regression in 3.3.1GA though. We were upgrading from 3.2.5GA and this is not required to use C3P0 in 3.2.5GA(and before). For us, we started having JDBC Connection exceptions on our test server because MySQL would close them after 8 hours. After turning on hibernate info logging, I noticed that it was using the built-in connection pool instead of c3p0 even though the same hibernate.cfg.xml was used for both hibernate versions.

Also, you need to use hibernate.c3p0.* instead of just c3p0.* in the hibernate.cfg.xml. It'll use the hibernate defaults if you don't. This is also a bit confusing because the reference docs maintained by the Hibernate team correctly say to user hibernate.c3p0.* and this page : http://www.hibernate.org/214.html
says to use c3p0.*
You can verify this by turning on the info(really warn is sufficient, but info will tell you everything) hibernate logging. You'll see a message about it overriding c3p0.* and using the hibernate.c3p0.* default values.


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