title: MySQLNonTransientConnectionException/jdbc4.CommunicationsException Errors Continuing while using C3P0
body: <p>I am running a Java web application using Hibernate and C3P0 as the connection pool, MySQL 5.6 database. I am continuing to run into issues on the deployed applications where the connections are timing out and generating errors:</p>
  
  <blockquote>
    <p>Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully
    received from the server was 426,126,080 milliseconds ago.  The last packet sent successfully to
    the server was 426,126,081 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.</p>
  </blockquote>
  
  <p>In particular, any period of inactivity will cause errors to start occurring. A long period caused errors such as these:</p>
  
  <blockquote>
    <p>(DefaultConnectionTester.java:148) [http-nio-8080-exec-9]: SQL State '08007' of Exception tested
    by statusOnException() implies that the database is invalid, and the pool should refill itself
    with fresh Connections. com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
    Communications link failure during commit(). Transaction resolution unknown.</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>(C3P0PooledConnectionPool.java:981) [http-nio-8080-exec-9]: A ConnectionTest has failed,
    reporting that all previously acquired Connections are likely invalid. The pool will be reset.</p>
  </blockquote>
  
  <p>Hibernate/C3P0 connection params are:</p>
  
  <pre><code>&lt;property name="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt;
  &lt;property name="hibernate.c3p0.initial_pool_size"&gt;5&lt;/property&gt;
  &lt;property name="hibernate.c3p0.min_size"&gt;5&lt;/property&gt;
  &lt;property name="hibernate.c3p0.max_size"&gt;50&lt;/property&gt;
  &lt;property name="hibernate.c3p0.acquire_increment"&gt;5&lt;/property&gt;
  &lt;property name="hibernate.c3p0.max_statements"&gt;500&lt;/property&gt;
  &lt;property name="hibernate.c3p0.timeout"&gt;1800&lt;/property&gt; &lt;!-- in secs --&gt;
  &lt;property name="hibernate.c3p0.idle_test_period"&gt;480&lt;/property&gt; &lt;!-- in secs --&gt;
  &lt;property name="hibernate.c3p0.testConnectionOnCheckout"&gt;false&lt;/property&gt;
  &lt;property name="hibernate.c3p0.testConnectionOnCheckin"&gt;true&lt;/property&gt;
  &lt;property name="hibernate.c3p0.preferredTestQuery"&gt;select 1&lt;/property&gt;
  &lt;property name="hibernate.c3p0.maxConnectionAge"&gt;3600&lt;/property&gt; &lt;!-- in secs --&gt;
  &lt;property name="hibernate.c3p0.numHelperThreads"&gt;8&lt;/property&gt;
  &lt;property name="hibernate.c3p0.maxIdleTimeExcessConnections"&gt;600&lt;/property&gt;
  </code></pre>
  
  <p>I have tried repeatedly to adjust the C3P0 parameters based on other comments on this topic and on the C3P0 docs, to no avail. The web application goes through periods of inactivity and heavy use, surely there must be some guidance on how the connection pooling should be configured in this use case, but I have yet to find any that have made a dent in this problem.</p>