title: Spring Boot: Communications link failure after some hours of inactivity with Hibernate, JDBC and MySQL
body: <p>I get this error if my Spring Boot application is inactive for several hours (e.g. during the night):</p>
  
  <pre><code>2015-05-19 09:16:32.666  WARN 20582 --- [http-nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 08S01
  2015-05-19 09:16:32.668 ERROR 20582 --- [http-nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper   : Communications link failure
  
  The last packet successfully received from the server was 29.792.613 milliseconds ago.  The last packet sent successfully to the server was 6 milliseconds ago.
  </code></pre>
  
  <p>Trying to solving this problem I read that <strong>MySQL</strong> have a parameter named <code>wait_timeout</code> setted by default to 8 hours (28800 seconds) and after this time all my inactive connections are closed, so my Spring Boot application stop to works... </p>
  
  <p>My questions are: </p>
  
  <ul>
  <li>How can I avoid this problem? </li>
  <li>Should I increase the value for such parameter? </li>
  <li>Are there any drawbacks increasing such value? (It could always be a value reached by my application if it is inactive so long.. :/ )</li>
  <li>Is not there another solution using <strong>Spring Boot</strong> (like a polling or something like that)?</li>
  </ul>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>There are other similar/useful questions here:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2912322/hibernate-communications-link-failure-in-hibernate-based-java-servlet-applicatio">Hibernate Communications Link Failure in Hibernate Based Java Servlet application powered by MySQL</a></li>
  <li><a href="https://stackoverflow.com/questions/28609565/spring-is-losing-connection-to-the-db-and-does-not-recover-or-reconnect">Spring is losing connection to the DB and does not recover or reconnect</a></li>
  <li><a href="https://stackoverflow.com/questions/15752667/warn-sqlexceptionhelper143-sql-error-0-sqlstate-08s01-sqlexceptionhelper">WARN SqlExceptionHelper:143 - SQL Error: 0, SQLState: 08S01- SqlExceptionHelper:144 - Communications link failure</a></li>
  <li><a href="https://stackoverflow.com/questions/16459990/sql-error-0-sqlstate-08s01-communications-link-failure">SQL Error: 0, SQLState: 08S01 Communications link failure</a></li>
  <li><a href="https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally">https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally</a></li>
  <li><a href="https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql">Solving a &quot;communications link failure&quot; with JDBC and MySQL</a></li>
  </ul>
  
  <p>From references above I can conclude that one solution is to add <strong>C3p0</strong> as additional library and properly configure it to avoid the communication link error..</p>
  
  <p>Is it the only solution I have? Isn't there a solution more "integrated" with Spring/Spring Boot (i.e. without adding an external library)?</p>