-->
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.  [ 2 posts ] 
Author Message
 Post subject: c3p0 in JPA
PostPosted: Tue Jul 14, 2009 7:46 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
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.


Top
 Profile  
 
 Post subject: Re: c3p0 in JPA
PostPosted: Wed Jul 15, 2009 4:11 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
I figured out what's wrong. Default connection manager was used instead of c3p0. c3p0 wasn't used because I used hibernate-core3.jar, which lacked c3p0 connection class. downloading proper hibernate3.jar fixed it.


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