We use C3P0 connection pooling like this and that solved a similar problem for us:
Code:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="preferredTestQuery" value="SELECT 1" />
<property name="idleConnectionTestPeriod" value="300" /> <!-- Test all connections in the pool every 5 minutes using the preferredTestQuery above -->
</bean>
Just using the MySQL-ConnectorJ autoReconnect=true parameter doesn't work here, because it still causes an exception to be thrown if the connection is stale, and only after that does the driver reconnect.