-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate MySQL connection timeout problem
PostPosted: Mon Jun 08, 2009 4:13 pm 
Newbie

Joined: Mon Jun 08, 2009 3:58 pm
Posts: 2
Hi everybody,

I ran into a problem while using Hibernate and Mysql. MySQL closes an unused connection after 28800 sec. I've googled. I thought I've found a solution, but it doesn't work.

For testing purposes I've set the MySQL timeout to 60 sec.

Attempt 1:

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>

      <!-- Database connection settings -->
      <property name="connection.driver_class">
         <!-- org.hsqldb.jdbcDriver -->
         com.mysql.jdbc.Driver
      </property>
      <property name="connection.url">
         jdbc:mysql://localhost/xxxx
      </property>
      <property name="connection.username">
         xxxx
      </property>
      <property name="connection.password">
         xxxx
      </property>

      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">1</property>

      [b]<!-- Timeout -->

      <property name="hibernate.c3p0.max_size">1</property>

      <property name="hibernate.c3p0.idle_test_period">20</property>
      <property name="hibernate.c3p0.timeout">40</property>[/b]

      <!-- SQL dialect -->
      <property name="dialect">
         <!-- org.hibernate.dialect.HSQLDialect -->
         org.hibernate.dialect.MySQLDialect
      </property>

      <!-- Enable Hibernate's automatic session context management -->
      <property name="current_session_context_class">thread</property>

      <!-- Disable the second-level cache  -->
      <property name="cache.provider_class">
         org.hibernate.cache.NoCacheProvider
      </property>

      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">false</property>

      <!-- Drop and re-create the database schema on startup -->
      <!-- comment this out to disable schema recreation on startup -->
      <!-- <property name="hbm2ddl.auto">create</property> -->
      <property name="hibernate.format_sql">false</property>

      <!-- Auflistung der gemappten Klassen -->
      ....

   </session-factory>

</hibernate-configuration>


Attempt 2: I've changed the bold part to
Code:
[b]<!-- Timeout -->

      <property name="c3p0.max_size">1</property>

      <property name="c3p0.idle_test_period">20</property>
      <property name="c3p0.timeout">40</property>[/b]


Attempt 3: I've included Hibernate C3P0 ConnectionProvider in version 3.3.1.GA in my project. Then I retried both former attempts, but I can't get it working.

It seems that the configurations I made have no effect.

Any hints? Solutions?

Regards,
Axel


Top
 Profile  
 
 Post subject: Re: Hibernate MySQL connection timeout problem
PostPosted: Tue Jun 09, 2009 10:33 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
I had this problem long back and solved most of it by modifying my MySQL database configuration as well. Did you had a chance to modify some of the parameters, most importantly one being the idle_time and the other being how much time a connection can remain active in your database and I remember the values in MySQL and hibernate are not of the same type, I mean both are not seconds?


Top
 Profile  
 
 Post subject: Re: Hibernate MySQL connection timeout problem
PostPosted: Tue Jun 09, 2009 11:02 pm 
Newbie

Joined: Tue Jun 09, 2009 10:52 pm
Posts: 9
I had this same issue and C3P0 was able to fix it. It looks like you might be missing the property for the connection provider.

Code:
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>


These are the properties I use with C3P0. I don't guarantee they are the best, but for a simple application they seem to be sufficient.

Code:
    <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="c3p0.acquire_increment">1</property>
    <property name="c3p0.idle_test_period">100</property>
    <property name="c3p0.max_size">100</property>
    <property name="c3p0.max_statements">0</property>
    <property name="c3p0.min_size">10</property>
    <property name="c3p0.timeout">100</property>


Hope this helps!


Top
 Profile  
 
 Post subject: Re: Hibernate MySQL connection timeout problem
PostPosted: Wed Jun 10, 2009 3:50 am 
Newbie

Joined: Tue Jun 09, 2009 4:33 am
Posts: 2
Hello,

I also have the same problem but I don't understand where is the problem.
I am using hibernate under JBOSS and it doesn't work all the time.
Sometimes it works and 5 minutes later it doesn't work, 5 minutes it works again without changing anything?

Is it the database that has a bad configuration or the hibernate configuration file that isn't good?

pvradhakrishna, you said that you had the same problem, how did you solve it? Only by using the c3P0 pool?
Or did you also change the configuration of MySQL.

Thanks for your help.


Top
 Profile  
 
 Post subject: Re: Hibernate MySQL connection timeout problem
PostPosted: Wed Jun 10, 2009 9:46 am 
Newbie

Joined: Tue Jun 09, 2009 10:52 pm
Posts: 9
For some reason the default pooling code which "Is not for production use" dropped the mysql connection. C3P0 was able to maintain the connection better for me. I didn't have to make any changes to the MySql database.


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