Stefanie,
A c3p0 pool with the settings you have should recover from a database reset, but that doesn't mean you will never see an Exception. Stale Connections from the old database session will still be broken, and if those Connections have already been checked out, or if they are in the pool and not tested on checkout, the application will see the broken Connection, in the form of an Exception.
You can use c3p0 to minimize the likelihood that your application will see a stale Connection on database shutdown/restart. The most reliable means of preventing this is to set hibernate.c3p0.validate to true (in a hibernate application -- all other c3p0 apps should use the c3p0-native property c3p0.testConnectionOnCheckout). If you set this property to true, c3p0 will test Connections prior to checkout, and your app will never see a stale Connection on database restart unless the Connection had already been checked out when the database went down.
Another less reliable, but potentially less expensive, strategy is to set c3p0.testConnectionsOnCheckin and hibernate.c3p0.idle_test_period (c3p0-native c3p0.idleConnectionTestPeriod) to a low value, in which case all connection tests are asynchronous and you are guanteed that no Connection will be checked out that hasn't been tested in the last idle_test_period seconds. Thus, your app will only see broken Connections from the pool if Connections are checked out during a short window of time.
In either case, I recommend setting "c3p0.preferredTestQuery" or "c3p0.automaticTestTable" in your c3p0 properties file, as c3p0's default Connection test is often slow.
See "Configuring Connection Testing" in c3p0's docs for more information.
Hope this helps!
Steve (c3p0 guy)
|