Hi,
I have a very strange problem after upgrading the hibernate core from version 3.3.2 to 5.0.2 Final and c3p0 from 0.9.1 to 0.9.2.1. We are using also hibernate-c3p0 5.0.3.Final. Here is the case. We are deleting on chunks the entries from a some table with logs. It is possible for our users to define the the chunk size and a sleep time between every chunk. We are opening a session, then for every chunk a transaction begins. There is no problem with the first several transactions, but after the 6th minute of opening the session there is an exception "
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed." when beginning the transaction. I have debugged it and the exception is thrown in
org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor in the
begin() method when setting auto commit to false. Actually I can go a little bit deeper so I can find that the exception is thrown in
com.mchange.v2.c3p0.impl.NewProxyConnection in
setAutoCommit(boolean a) method where the value is set, no further. I can reproduce it also when I put a break point before entering the begin transaction, wait for 6 minutes or more and step in. I have tried to check if the session is opened and connected before entering the begin transaction. Even if I wait for 15 minutes, the session is still opened and connected, but a second later the exception is thrown. We have:
hibernate.c3p0.timeout="1800",
hibernate.c3p0.preferredTestQuery="select 1",
hibernate.c3p0.min_size="2",
hibernate.c3p0.max_size="100" set.
I have found out about the 6 minutes because when setting sleep time of 30 seconds, there are 12 transactions executed, on the 13th it fails. Is it possible that we have to set some new property? I did not find such. I have read the change log of c3p0, but I am not sure that I have understood all of the changes. The problem is observed with MySQL and MSSQL, so I do not thing that it is database specific. Here is the code:
Code:
//the session is defined somewhere here
try {
session = mSessionFactoryManager.getSessionFactory().openSession();
for (Long toDateMillis : deleteTimes) {
Transaction tx = session.beginTransaction(); //fails here everytime on the 6th minute
Query dq = session.createQuery(deleteQuery);
//doing some stuff
tx.commit();
if(sleepTime > 0) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
sLogger.debug("Deleting logs ", e);
}
}
}
} finally {
session.close();
}
I do not know what to do any more. There is no such problem with the older version of our product that uses the old libraries. I am still a beginner with hibernate. If you think that the question is not for this forum, please excuse me and delete the topic. Thank you.
Regards.