title: MySQLNonTransientConnectionException after server has not been accessed for hours
body: <p>There is a Grails2.2/Hibernate/Tomcat7/MySQL5.5 web server. After none web client has requested it for hours, the first request to it fails as follows. (In fact, it happens every morning.) Any sequential requests are handled correctly.</p>
  
  <p>I instructed MySQL driver to <code>?autoReconnect=true</code> but it didn't help.</p>
  
  <p>A rollback could be noticed below but I do not call it directly from my code. Instead it happens implicitly when trying to persist an object after the long pause.</p>
  
  <p>Any idea to cure that?</p>
  
  <pre><code>Error 500: Executing action [actionName] of controller [MyController] caused exception: Runtime error executing action
  Servlet: grails
  URI: /appname/grails/appName/actionName.dispatch
  Exception Message: Communications link failure during rollback(). Transaction resolution unknown. 
  Caused by: Communications link failure during rollback(). Transaction resolution unknown. 
  Class: MyController 
  At Line: [139] 
  Code Snippet:
  
  com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.Util.getInstance(Util.java:386)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1014)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
      at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4808)
      at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368)
      at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323)
      at MyController.logRequest(...)
      ...
      at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
      at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:636)
  </code></pre>
  
  <p>Tomcat's context.xml:</p>
  
  <pre><code>&lt;Resource name="jdbc/JNDI_NAME" auth="Container"
   type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
   url="jdbc:mysql://localhost:3306/dbname?autoReconnect=true"
   username="xxx" password="xxx" maxActive="20" maxIdle="10"
   removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
   maxWait="-1"/&gt;
  </code></pre>