-->
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.  [ 6 posts ] 
Author Message
 Post subject: c3p0 - 2 problems
PostPosted: Tue May 03, 2005 2:37 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Hi,

I am facing two problems:

Problem 1: My c3p0 pool seems to be initialized twice when i start my tomcat service. I am using hibernate in a webapp. Specifically I see the "Initializing c3p0 pool .... " in the tomcat log twice at the startup of my tomcat service which loads my webapp. This has lead me to believe that c3p0 is being initialized twice. Does anyone have any idea as to why this might be happening and how do I rectify this if this is a problem?
(Note: I have no other webapp deployed in my tomcat webapps directory that uses Hibernate.)

Code:
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1fe8ce8 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@6ed322 [ acquireIncrement -> 3, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, maxIdleTime -> 0, maxPoolSize -> 15, maxStatements -> 0, minPoolSize -> 3, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@d4d66b [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost/test3, properties -> {user=xyz, password=password} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]


Problem 2: Once started I have no issues with the execution of my webapp. I use Hibernate in my webapplication. The problem occurs after the webapp is live on the server for an extended amount of time with no activity. I get an exception. I suspect that this might be due to my connections in the connection pool getting timed out or closing. Any ideas as to why thid might be happening?

Exception:

Code:
java.lang.RuntimeException: org.hibernate.exception.GenericJDBCException: Cannot open connection
com.ac.tan.persistence.daos.HBGenericDAO.findOneByQuery(HBGenericDAO.java:282)
com.ac.tan.persistence.daos.HBCartDAO.getCartId(HBCartDAO.java:33)
com.ac.tan.managers.ShoppingManagerImpl.getCartId(ShoppingManagerImpl.java:25)
com.ac.tan.web.filters.CookieFilter.getCartId(CookieFilter.java:82)
com.ac.tan.web.filters.CookieFilter.doFilter(CookieFilter.java:48)
com.ac.tan.web.filters.HibernateSessionFilter.doFilter(HibernateSessionFilter.java:31)


Hibernate version: 3.0

C3p0 version: c3p0-0.8.4.5.jar

Mapping document:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
       <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="hibernate.connection.url">jdbc:mysql://localhost/test3</property>
       <property name="hibernate.connection.username">xyz</property>
       <property name="hibernate.connection.password">password</property>
       <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
   
       <property name="show_sql">true</property>
       <property name="transaction.factory_class">
            org.hibernate.transaction.JDBCTransactionFactory
       </property>
   
       <property name="hibernate.cache.provider_class">
            org.hibernate.cache.EhCacheProvider
       </property>
   
       <property name="hibernate.hbm2ddl.auto">update</property>
   
      <!-- c3p0 connection pool settings -->
      <property name="hibernate.c3p0.acquire_increment">3</property>
      <property name="hibernate.c3p0.max_size">15</property>
      <property name="hibernate.c3p0.min_size">3</property>
         
       <mapping resource="com/ac/tan/beans/Beans.hbm.xml"/>       
   </session-factory>
</hibernate-configuration>


Name and version of the database you are using: MySQL 4.1


Top
 Profile  
 
 Post subject: Does anybody have the above problems?
PostPosted: Thu May 05, 2005 3:18 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
I have tried to find out

(A) why the connections from my c3p0 connection pool are timing out? and

(B) why the connection pool is being initialized twice when I start my webapp in tomcat?

Has anybody run into the above two problems and do you know the solution to them?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 5:25 am 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
hi.

mysql Connections usually time out after some period of time. you should configure c3p0 to test connections on checkout and/or to time out idle connections.

please upgrade to at least c3p0-0.8.5.2, which will let you set a preferredTestQuery. For mysql, 'SELECT 1' is known to work well. if you set this preferredTestQuery, the performance cost of connection testing will be very significantly reduced. also (or instead), find out from your mysql config how long mysql connections are permitted to remain inactive before timing out. set c3p0's maxIdleTime parameter to about half this time.

be careful when configuring hibernate and c3p0 parameters, because some of the configuration has to be done in your hibernate config, and some in a c3p0.properties file. read c3p0's docs (especially http://www.mchange.com/projects/c3p0/in ... appendix_d ) carefully, and verify in the config dump in your logs that the parameters you intended were in fact set.

i'm not sure why you would be seeing two datasources initialized.

smiles,
Steve (c3p0 guy)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 1:16 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Hi,

I did a test last evening that I just verified this morning that it works.

I put this line:
Code:
      <property name="hibernate.c3p0.idle_test_period">100</property>


in the hibernate.cfg.xml file and I am no longer getting the exception.

Yes, the parameters I set are being set. The only other issue I cannot understand is the c3p0 being initialized log appearing twice in my logs.


Que: I can upgrade to c3p0-0.8.5.2. Is the "SELECT 1" a better method than using the - hibernate.c3p0.idle_test_period property ??


Thank you.


Top
 Profile  
 
 Post subject: Figured out the second problem
PostPosted: Fri May 06, 2005 1:33 pm 
Beginner
Beginner

Joined: Sun Feb 20, 2005 12:14 am
Posts: 49
Hi,

For what its worth, I was getting the two logs - "Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@3a5794 [ connectionPoolDataSource -> .....

due to this property:

Code:
<property name="hibernate.hbm2ddl.auto">update</property>


I am setting this in my hibernate.cfg.xml to update my database schema when I create a sessionFactory.

Hope this helps someone else.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 6:05 am 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
"Que: I can upgrade to c3p0-0.8.5.2. Is the "SELECT 1" a better method than using the - hibernate.c3p0.idle_test_period property ?? "

mkhumri -- it's not an either or thing. hibernate.c3p0.idle_test_period property affects how frequently idle Connections will be tested, c3p0.preferredTestQuery affects what will happen on each of those Connection tests.

if you are testing Connections (especially if you are testing them on checkout, or very frequently), you'll be better off setting a c3p0.preferredTestQuery (such as "SELECT 1" under mysql) or c3p0.automaticTestTable than not. (You do have to upgrade at least to c3p0-0.8.5.x to use these features.) The default Connection test is schema independent, but quite slow.

smiles,
Steve


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