Hibernate version: 3.1.3
c3p0 version: 0.9.0.4
jtds version: 1.2
I am using Hibernate with
ThreadLocalSessionContext. My application is a service running all the time. It is importing data every night and then pausing for 20 hours. Sometimes i got exceptions when it starts importing:
Code:
2007-12-11 03:10:11,142 ERROR [com.carano.dsw.preisabruf.impl.PreisgruppenabrufImpl] Error while Importing.
org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1283)
at sun.reflect.GeneratedMethodAccessor151.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy107.beginTransaction(Unknown Source)
at com.carano.dbfleet.vertrag.hibernate.VertragImportHibernateHandler.suchePreislisteDsw(VertragImportHibernateHandler.java:1002)
Here is the code:
Code:
public PreislisteDsw suchePreislisteDsw( final String systemBezeichnung )
{
final Session session = HibernateUtil.getCurrentSession();
final Transaction tx = session.beginTransaction();
PreislisteDsw preisliste = null;
try
{
final Criteria criteria = session.createCriteria( PreislisteDsw.class );
criteria.add( Restrictions.eq( "systembezeichnung", systemBezeichnung ) );
preisliste = (PreislisteDsw) criteria.uniqueResult();
tx.commit();
}
catch( final HibernateException e )
{
if( tx!=null )
{
tx.rollback();
}
final String meldung = "Error while searching for Preisliste-Dsw.";
LOG.error( meldung, e );
throw new RuntimeException( meldung, e );
}
return preisliste;
}
I am always using the session this way:
* HibernateUtil.getCurrentSession()
* session.beginTransaction()
* tx.commit() or tx.rollback()
* HibernateUtil.getCurrentSession()
* ..
After pausing the service gets sessions which are closed from getCurrentSession sometimes. This is not a multi threading issue. There is only one thread working.
The database connection is unstable because of networking trouble. I am using c3p0 connection pool. c3p0 is configured to throw away connections from the pool which are idle for 100s.
Do you know help or a workaround?