Connection timeouts when upgrading hibernate version

In our codebase, some modules are running old version of hibernate 3.6.0. Other modules are running relatively newer version 4.1.7. Everything is working correctly. We have MySQL DB.

Now we started the effort to systematically migrate to latest version of hibernate.

First we decided to migrate the modules running on 3.6.0 to 4.1.7 so that all modules have the same hibernate version. When we do this, everything runs perfectly for like an hour. Then the performance of our website starts rapidly degrading, and finally we see that the hibernate queries just hang till they timeout. We see no exceptions (all code is in try/catch).

Question: What can be the reason for this timeout? Is it possible that the connection pool is getting full?

FYI - Some months ago we had seen similar symptom in another part of the code which was missing entityManager.close(). At that time the minute we added entityManager.close() the problem resolved. So we have scanned our entire code several times to make sure we close all entityManagers properly. Again, note that there is no problem if we switch back to 3.6.0. We tried upgrading to a 4.2.21 version of hibernate, which is newer than 4.1.7, in case that would help. But it has not helped.

Can you please advice what our next step should be to debug/resolve this issue?

You need to activate logging both on the application and the database side and see which queries are blocking.

Also, run some stats queries on the database to see which queries are stuck.

It’s impossible to tell what’s wrong without seeing the code.

Thanks for the response. Here is some more things we discovered on investigation:

  • Entitymanager is not able to communicate with database.
  • When we see this problem, there is no active connections in the database. We checked in database by running SHOW PROCESSLIST command.
  • Ideally there should be 5 active connections for each application because we have:
    <property name=“hibernate.c3p0.min_size” value=“5” />

Here is our full property settings:

<property name=“hibernate.dialect” value=“org.hibernate.dialect.MySQLInnoDBDialect” />
<property name=“” value=“validate” />
<property name=“hibernate.ejb.naming_strategy” value=“com.c2m.persistence.mol.NamingStrategy” />
<property name=“javax.persistence.jdbc.driver” value=“com.mysql.jdbc.Driver” />
<property name=“hibernate.showSql” value=“true” />
<property name=“hibernate.c3p0.min_size” value=“5” />
<property name=“hibernate.c3p0.max_size” value=“20” />
<property name=“hibernate.c3p0.timeout” value=“500” />
<property name=“hibernate.c3p0.max_statements” value=“50” />
<property name=“hibernate.c3p0.idle_test_period” value=“300”/>
<property name=“hibernate.c3p0.preferredTestQuery” value=“SELECT 1;” />
<property name=“hibernate.c3p0.testConnectionOnCheckout” value=“true” />
<property name=“hibernate.connection.provider_class” value=“org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider” />
<property name=“hibernate.connection.useUnicode” value = “true”/>
<property name=“hibernate.connection.characterEncoding” value = “UTF-8”/>
<property name=“hibernate.c3p0.maxIdleTime” value=“10800” />
<property name=“hibernate.c3p0.maxIdleTimeExcessConnections” value=“600”/>

Any idea what might be happening? Why the connection pool is going to zero open connections?

  1. The C3P0ConnectionProvider is located in the org.hibernate.c3p0.internal package. Remove the hibernate.connection.provider_class configuration because it’s not needed. Hibernate will know you are using c3p0.
  2. There’s no URL, user, password settings so Hibernate will not know how to connect to the DB.