title: Hibernate JDBCConnectionException - C3p0 connection pooling
body: <p>We are using C3p0 connection pooling for our mysql db using HibernateORM.</p>
  
  <p>Below are the settings in hibernate.cfg.xml</p>
  
  <pre><code>&lt;property name="hibernate.c3p0.acquire_increment"&gt;1&lt;/property&gt;
  &lt;property name="hibernate.c3p0.idle_test_period"&gt;300&lt;/property&gt;
  &lt;property name="hibernate.c3p0.maxConnectionAge"&gt;3600&lt;/property&gt;
  &lt;property name="hibernate.c3p0.timeout"&gt;120&lt;/property&gt;
  &lt;property name="hibernate.c3p0.max_size"&gt;300&lt;/property&gt;
  &lt;property name="hibernate.c3p0.min_size"&gt;1&lt;/property&gt;
  &lt;property name="hibernate.c3p0.max_statements"&gt;100&lt;/property&gt;
  &lt;property name="hibernate.c3p0.preferredTestQuery"&gt;select 1;&lt;/property&gt;
  </code></pre>
  
  <p>And for reconnection to the database after 28800 seconds we set the params - </p>
  
  <pre><code>c3p0.testConnectionOnCheckout=true
  </code></pre>
  
  <p>But we are facing hibernate exceptions.</p>
  
  <p>So if I make a call to the DB now and wait for 8 hours ( or whatever amount of time I set the variable wait_timeout of my.cnf ), I get that exception if I make another call to the DB . 
  stacktrace -</p>
  
  <pre><code>org.hibernate.exception.JDBCConnectionException: could not execute query
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
          at org.hibernate.loader.Loader.doList(Loader.java:2536)
          at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
          at org.hibernate.loader.Loader.list(Loader.java:2271)
          at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
          at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
          at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
          at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
          at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
  </code></pre>
  
  <p>As a quick fix to the issue, we are restarting the app server every day morning.</p>
  
  <p>Any help would be appreciated</p>
  
  <p>--
  Thanks</p>