I found out what's going on. MySQL times out, but c3p0 can't recognize when it happens, so we have to restart the pooled connections before MySQL times out.
- First, I created a new file in my classpath called
c3p0-config.xml
where I can put all my c3p0 settings. I don't know if this actually helps anything, but I wanted to dissociate c3p0 with hibernate anyway. Then, I put this in the new config file:
<c3p0-config> <default-config> <property name="acquireIncrement">3</property> <property name="idleConnectionTestPeriod">5</property> <property name="maxConnectionAge">30</property> <property name="maxIdleTime">10</property> <property name="maxPoolSize">25</property> <property name="maxStatements">0</property> <property name="minPoolSize">5</property> <property name="preferredTestQuery">SELECT 1</property> <property name="testConnectionOnCheckin">true</property> <property name="testConnectionOnCheckout">true</property> </default-config> </c3p0-config>
The big things are maxConnectionAge
and maxIdleTime
, which dicard connections that are so many seconds old. A description of all the variables can be found here.
This doesn't solve all my problems with my project, but at least this bug is fixed.