tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Eggers <>
Subject Re: Exception in hibernate3 relating to timeout
Date Fri, 25 Feb 2011 19:20:09 GMT
----- Original Message (edited) ----
From: Filip Hanik - Dev Lists <>

Use a different connection pool that can properly handle your timeouts 
when idle.


On 02/24/2011 11:31 PM, abhishek jain wrote:
> hi,
> I am not sure if i am ringing the correct list, but i am sure people here
> must have encountered this problem. I am new to hibernate and when i ran the
> code on server it was fine , strangely next day it keep on giving this error
> till i restart tomcat.
> The last packet successfully received from the server was 54,880,316
> milliseconds ago.  The last packet sent successfully to the server was
> 54,880,317 milliseconds ago. is longer than the server configured value of
> 'wait_timeout'. You should consider either expiring and/or testing
> connection validity before use in your application, increasing the server
> configured values for client timeouts, or using the Connector/J connection
> property 'autoReconnect=true' to avoid this problem.
> I have searched a lot on net and added the following properties on
> hibernate.cfg.xml, as people there were suggesting this,but of no use.
> <!-- Sessions and transactions -->
> <!-- Use the C3P0 connection pool provider -->
> <property name="hibernate.c3p0.min_size">5</property>
> <property name="hibernate.c3p0.max_size">20</property>
> <property name="hibernate.c3p0.timeout">300</property>
> <property name="hibernate.c3p0.max_statements">50</property>
> <property name="hibernate.c3p0.idle_test_period">3000</property>
> <property name="current_session_context_class">thread</property>

----- Original Message (edited) ----

Agreed, a better pooling system would be preferable. A Wiki entry on how to 
couple Hibernate and Tomcat's JNDI pooling can be found here:

If you add a validation query to your Resource definition, then you can recover 
from stale connections. For MySQL, the validation query is:

validationQuery="SELECT 1"

So in the Wiki example (from above), the modified context.xml file would look 

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true">
    <Resource auth="Container"
              validationQuery="SELECT 1"/>

Apparently another way you can do this is with C3P0 properties - in particular 
connection testing.

Documentation can be found on the web. See:

for pointers. You can define a preferredTestQuery, but I am unsure if you have 
to use HQL syntax or the validationQuery listed above.

Also according to the references, extra C3P0 properties need to be placed in a 
separate file that lives somewhere on the application's class 
path. To make sure your property file ends up in WEB-INF/classes, you'll have to 
figure out where to place it in MyEclipse.

I've not tried connection testing with C3P0, since I use the Tomcat-managed 
connection pooling mechanism.

. . . . just my two cents.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message