----- Original Message (edited) ----
From: Filip Hanik - Dev Lists <devli...@hanik.com>

Use a different connection pool that can properly handle your timeouts 
when idle.
http://people.apache.org/~fhanik/jdbc-pool/
http://people.apache.org/~fhanik/jdbc-pool/jdbc-pool.html

Filip

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:

http://wiki.apache.org/tomcat/TomcatHibernate

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 
like:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true">
    <Resource auth="Container"
              driverClassName="com.mysql.jdbc.Driver"
              maxActive="30"
              maxIdle="10"
              maxWait="10000"
              name="jdbc/sakila"
              password="*****"
              username="*****"
              url="jdbc:mysql://localhost/sakila"
              type="javax.sql.DataSource"
              validationQuery="SELECT 1"/>
</Context>

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

Documentation can be found on the web. See:

http://community.jboss.org/wiki/HowToconfiguretheC3P0connectionpool
http://www.mchange.com/projects/c3p0/index.html#appendix_a

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 c3p0.properties 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.

/mde/


      

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to