Я использую Hibernate 4.3.11 с H2 1.4.199
Для защиты от случайных сессий, которые кажутся застрявшими, я установил
config.setProperty("hibernate.c3p0.debugUnreturnedConnectionStackTraces", "true");
config.setProperty("hibernate.c3p0.unreturnedConnectionTimeout","1500");
, и после этого c3p0 освобождает соединение после этого времени. period
java.lang.Exception: DEBUG STACK TRACE: Overdue resource check-out stack trace.
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:555)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:90)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1471)
at com.jthink.songlayer.hibernate.HibernateUtil.beginTransaction(HibernateUtil.java:209)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher.call(MusicBrainzSongGroupMatcher.java:469)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher1.call(MusicBrainzSongGroupMatcher1.java:84)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher1.call(MusicBrainzSongGroupMatcher1.java:37)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Проблема в том, что мой код использует это недействительное соединение, которое HIbernate, похоже, не знает, что оно было отменено
org.h2.jdbc.JdbcSQLNonTransientException: The object is already closed [90007-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:502)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.message.DbException.get(DbException.java:170)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1568)
at org.h2.jdbc.JdbcConnection.checkClosedForWrite(JdbcConnection.java:1557)
at org.h2.jdbc.JdbcConnection.rollback(JdbcConnection.java:561)
at com.mchange.v2.c3p0.impl.NewProxyConnection.rollback(NewProxyConnection.java:860)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:163)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:211)
at com.jthink.songkong.util.SessionUtil.rollback(SessionUtil.java:25)
at com.jthink.songkong.analyse.analyser.RecordingOnlyMatcher.matchRecordingsOnlyByAcoustid(RecordingOnlyMatcher.java:452)
at com.jthink.songkong.analyse.analyser.AbstractMusicBrainzGroupMatcher.matchSongs(AbstractMusicBrainzGroupMatcher.java:138)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher1.doTask(MusicBrainzSongGroupMatcher1.java:418)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher.call(MusicBrainzSongGroupMatcher.java:470)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher1.call(MusicBrainzSongGroupMatcher1.java:84)
at com.jthink.songkong.analyse.analyser.MusicBrainzSongGroupMatcher1.call(MusicBrainzSongGroupMatcher1.java:37)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Хотя в моем коде я проверяю, что мой сеансopen, txn active ectera
public static void rollback(Session session)
{
try
{
if (session!=null && session.isOpen() && session.getTransaction() != null && !session.getTransaction().wasRolledBack())
{
session.getTransaction().rollback();
}
}
catch(HibernateException he)
{
//Hide erorr cause can occur after timeout txn
MainWindow.logger.log(Level.SEVERE, he.getMessage(), he);
}
}
кажется, что они не предотвращают вызов rollback () и затем его завершение, у меня похожие проблемы с session.close ()