title: Grails/Tomcat/MySQL stale connection error, even when using JNDI?
body: <p>I have a couple of Grails 1.3.3 application running on Tomcat 6.0.18.  I'm aware of the database connection staleness issue when using the default Grails datasource (connection gets killed after a period of inactivity), so I switched to JNDI provided by Tomcat.</p>
  
  <p>The first app I deployed has never had any stale database connection problems.  Now I deployed a second app to the same server with the same JNDI datasource configuration, and while the first continues to work fine, the second app gets the connection timeout error after about 8 or so hours of inactivity.  (After the error the connection gets refreshed and it works just fine again)</p>
  
  <p>The datasources are defined in Tomcat's context.xml as follows:</p>
  
  <pre><code>&lt;Resource name="jdbc/firstDs" auth="Container" type="javax.sql.DataSource"
          maxActive="100" maxIdle="30" maxWait="10000"
          username="user1" password="password1" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/firstApp" /&gt;
  
  &lt;Resource name="jdbc/secondDs" auth="Container" type="javax.sql.DataSource"
      maxActive="100" maxIdle="30" maxWait="10000"
      username="user2" password="password2" driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/secondApp" /&gt;
  </code></pre>
  
  <p>Both of the apps use the JNDI datasource in the Datasource.groovy file as follows (everything is exactly the same, except for the jndiName):</p>
  
  <pre><code>dataSource {
      pooled = false
  }
  ...
  environments {
      ...
      production {
          dataSource {
              dbCreate = "update"
              jndiName = "java:comp/env/jdbc/firstApp"
          }
      }
  }
  </code></pre>
  
  <p>The <strong>ONLY</strong> difference I'm aware of between these 2 situations is that working app uses MyISAM tables, while the non-working app uses InnoDB tables.  Has anyone experienced an issue with InnoDB and Tomcat connection pooling?  I may try switching to MyISAM if I can't find anything else to try.</p>