-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to use c3p0
PostPosted: Fri May 14, 2010 10:37 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I'm using Hibernate and EntityManager 3.5.1-Final.

I'm monitoring the number of connections using pgadmin3 and I'm seeing that my application makes more connection than specified in the persistence.xml.

Here's my persistence.xml. And I'm getting and closing EntityManager for every request.

Code:
<persistence 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_2_0.xsd"
             version="2.0">
   <persistence-unit name="bank" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <class>com.wms.bank.entities.GameAccount</class>
      <class>com.wms.bank.entities.StationAccount</class>
      <class>com.wms.bank.entities.PlayerAccount</class>
      <properties>
         <property name="hibernate.archive.autodetection" value="none"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.bytecode.use_reflection_optimizer" value="false"/>
         
         <!-- Database specific -->
         <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
         <property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1/bank?user=postgres;password=postgres"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
         
         <!-- Connection pool -->
         <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
         <property name="hibernate.c3p0.acquire_increment" value="0"/>
         <property name="hibernate.c3p0.idle_test_period" value="100"/> <!-- seconds -->
         <property name="hibernate.c3p0.max_size" value="10"/>
         <property name="hibernate.c3p0.max_statements" value="0"/>
         <property name="hibernate.c3p0.min_size" value="5"/>
         <property name="hibernate.c3p0.timeout" value="100"/> <!-- seconds -->
      </properties>
   </persistence-unit>
</persistence>


Am I missing something?

Thanks

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject: Re: How to use c3p0
PostPosted: Fri May 14, 2010 10:51 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I think I figured out my problem. I'm actually running a junit test and apparently new instance of my app gets created for every test case and that created a pool everytime.

I do have another question though. When are connections released back to the pool?

I keep running out of connections (even when I set my max_size to 100) I don't have that many concurrent requests.

Thanks
Budyanto

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject: Re: How to use c3p0
PostPosted: Sun May 23, 2010 1:52 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
freak ;).....heh, it's been a while. Thanks for the post. How's chicago?

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


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