You really have to go to the C3P0 connection pool: http://www.mchange.com/projects/c3p0/index.html#hibernate-specific
The C3P0 documentation on this subject has a section: http://www.mchange.com/projects/c3p0/index.html#configuring_recovery
First you need to configure c3p0 correctly, which, if you use hibernate, should happen in the c3p0.properties file.
In your c3p0.properties put these properties to reconnect indefinitely every 3 seconds when the database is down:
c3p0.acquireRetryAttempts = 0 c3p0.acquireRetryDelay = 3000 c3p0.breakAfterAcquireFailure = false
In addition, in order not to damage the connections lying in your pool indefinitely, use the connection age control:
c3p0.maxConnectionAge = 6000 c3p0.maxIdleTime = 6000 c3p0.maxIdleTimeExcessConnections = 1800 c3p0.idleConnectionTestPeriod = 3600
It can be quite expensive, but useful if the above is not enough:
c3p0.testConnectionOnCheckout = true c3p0.preferredTestQuery = SELECT 1;
You can also check for leaks in connections that prevent recovery:
c3p0.debugUnreturnedConnectionStackTraces = true
Finally, make sure that C3P0 is connected correctly to hibernate, enable debugging logging for the com.mchange package and see if C3P0 notifies itself. It should contain the configuration properties that are loading, so see if this is all.
Hope this helps.
Spajus
source share