-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: getCurrentSession(), Session is closed!
PostPosted: Tue Dec 11, 2007 11:47 am 
Beginner
Beginner

Joined: Tue Sep 16, 2003 11:26 am
Posts: 25
Location: Berlin - Germany
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?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 1:31 pm 
Beginner
Beginner

Joined: Tue Sep 16, 2003 11:26 am
Posts: 25
Location: Berlin - Germany
The reason for my problems is network trouble. There is no save network connection to the database. Best workaround so far: After retrieving the hibernate session from the session factory:
Session session = hibernateSessionFactory.getCurrentSession();
i test it:
if( !session.isOpen() )
If it is not open i create a totally new new session factory.
Creating new session factories all the time is a performance and memory risk. Its only a workaround!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.