I am using C3P0 0.9.1 as a connection pool for my Hibernate 3.2 application which is accessing a POstgreSQL 8.3 database.
The application is a rich-client Swing app which connects to the database directly over the internet.
Since PostgreSQL connections get broken quite often over the internet (never happens on the local net) we now would like to test our connections on checkout from the connection pool.
We configure Hibernate with C3P0, activating connection testing with the "validate" parameter: hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider hibernate.c3p0.min_size=0 hibernate.c3p0.initial_size=0 hibernate.c3p0.acquire_increment=1 hibernate.c3p0.validate=true
We also provide connection testing settings in the C3P0.properties file: testConnectionOnCheckout=true preferredTestQuery=select 1 from core_sys_settings
For some reason, we still get broken connections from the connection pool when using SessionFactory.openSession(), so the newly created Session is also broken. We test the connection-testing by forcibly killing the connections on the server (with kill PID) and see what happens on the client.
If I understand correctly, Hibernate checks out a connection for every newly opened session right? When it checks the connection out, C3P0 should test the connection as its configuration says. If it finds a broken connection, it should open a new and return the new connection for the session. Still, it doesn't seem to happen in every case.
Is it possible that Hibernate checks out a connection from the pool only in certain cases? How can I make sure, the connection gets tested during openSession() and I always get a working connection.
|