I recently upgraded the version of Hibernate and C3P0 in my application from
Hibernate-3.2.7.ga.jar and c3p0-0.9.1.2.jar
TO
hibernate-core-3.3.2.GA.jar hibernate-c3p0-3.3.2.GA.jar
There was no good reason for me to do this, it simply seemed appropriate to try a more recent version and tests did not reveal any problem.
Everything appeared to work fine in testing, but there is some sort of subtle problem in production. Things will work fine, and then after maybe about an hour the connectivity breaks down. The first sign comes from my connection pool
2011-03-10 09:02:06,967 [dbpool/26] ERROR util.JDBCExceptionReporter - Communications link failure
The last packet successfully received from the server was 1,292,776 milliseconds ago. The last packet sent successfully to the server was 36 milliseconds ago.
2011-03-10 09:02:06,968 [dbpool/26] ERROR dao.CallStatsDao - HibernateException
org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:328)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Once this happens no database connections work.
Interestingly, perhaps, there are three application servers, one of which is on the same network as the database server, the other two not. The one that is on the same network does not experience this problem.
These are my c3p0 settings. They are unchanged from the previous version's.
Code:
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=600
hibernate.c3p0.max_statements=50
hibernate.c3p0.acquire_increment=2
hibernate.c3p0.idle_test_period=300
Unless someone can offer an explanation about what might be going on here, my immediate approach is going to be to revert hibernate and c3p0 to the previous version. I can't think of anything else.