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