Hi there,
I have a big problem with hibernate and MySQL and c3p0.
I am using Hibernate Entity manager and get the transactions through the factory manager like this
Code:
public class HibernateUtil {
private static final EntityManagerFactory emf;
static {
try {
emf = Persistence.createEntityManagerFactory("AgaderPU");
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static EntityManagerFactory getEntityManagerFactory() {
return emf;
}
}
Here is my persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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_1_0.xsd">
<persistence-unit name="AgaderPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>xxx.xxx.xxx.XBean</class>
<properties>
<!-- use a file system based index -->
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<!-- directory where the indexes will be stored -->
<property name="hibernate.search.default.indexBase" value="/indexes"/>
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.connection.url" value="jdbc:mysql://boqueixon:3306/*****"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="****"/>
<property name="hibernate.connection.username" value="****"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.c3p0.acquire_increment" value="1"/>
<property name="hibernate.c3p0.idle_test_period" value="5"/>
<property name="hibernate.c3p0.timeout" value="5"/>
<property name="hibernate.c3p0.max_size" value="5"/>
<property name="hibernate.c3p0.max_statements" value="100"/>
<property name="hibernate.c3p0.min_size" value="1"/>
<property name="hibernate.c3p0.min_pool_size" value="1"/>
<property name="hibernate.c3p0.max_pool_size" value="5"/>
</properties>
</persistence-unit>
</persistence>
I have configured C3P0 to just use a max of five connections for testing purposes
The problem is after i refresh 5 times my aplication hangs. It doesnt really hang it just doesnt give any error and the browser waits loading for ever. When i debug i see that the program gets the entity manager ok but as soon as a query.getResultList() is executed the breakpoint flies away and the program keeps running but without executing any statements. Its as if the program is waiting for Mysql to reply but it never does.
This depends on the number i give to hibernate.c3p0.max_size. If i give 5 then i can refresh 5 times with perfect execution but the sixth hangs and waits for ever.
The other thing is that mysql has wait_timeout = 60 seconds.
If i limit the hibernate.c3p0.timeout to 30 it doesnt seem to respond. For example i execute my program and wait for 120 seconds and hit refresh. The program executes but gives me an error that the connection is closed. Its as if hibernate keeps the mysql timedout connections
Please help