I'm having a trouble with my application. The application runs on Tomcat 5.5, uses MySql 5.1 and JPA with Hibernate implementation.
The problem is that the connections aren't closed. Executing query with this code:
Code:
EntityManager em = emf.createEntityManager();
Query query = this.getQuery(sc, pageNumber, em);
List<TransactionDB> results = query.getResultList();
em.close();
leaves 2 threads in 'sleep' mode on mysql server. I have set all basic c3p0 properties in persistence.xml:
Code:
<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="KsiegowoscPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>pl.cetelem.ksiegowosc.db.entity.TransactionDB</class>
<class>pl.cetelem.ksiegowosc.db.entity.FileDB</class>
<class>pl.cetelem.ksiegowosc.db.entity.AddressDB</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://dev.ctlm.pl/ksiegowosc?characterEncoding=Cp1250"/>
<property name="hibernate.connection.username" value="ksiegowosc"/>
<property name="hibernate.connection.password" value="ksiegowosc"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="10"/>
<property name="hibernate.c3p0.timeout" value="60"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="100"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="none"/>
</properties>
</persistence-unit>
</persistence>
Despite setting c3p0 timeout property to 60, all connection threads last much much longer than that. I'm not sure but it seems that all c3p0 properties are ingored (for example max_size is set to 1 or 2 and 10 users are able to simultaneously execute queries).
I dont' know why, but executing the same query locally (via Netbeans) closes the connections and there are no threads left on Mysql server.
Why is that, am I missing some basic point here? All hints are highly appreciated.