-->
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: Coding idiom for Hibernate?
PostPosted: Wed Apr 21, 2004 12:07 pm 
Newbie

Joined: Mon Apr 19, 2004 7:10 pm
Posts: 7
I need to establish a coding idiom for use with Hibernate. The following method has an extra level of try-catch in a finally block.

Is this required or can I simply put the session.close() in the first block? Will Hibernate automatically close a session if there is an exception thrown?

Code:
private List findDomainObjects( String query )
  {
  List result = java.util.Collections.EMPTY_LIST;

  try
    {
    Session session = sessionFactory.openSession( conn );
    result = session.find( query );
    }
  catch ( HibernateException he )
    {
    cat.warn( "Hibernate error during query", he );
    }
  catch ( Exception e )
    {
    cat.fatal( "Serious internal error.", e );
    }
  finally
    {
    try
      {
      session.close();
      }
    catch ( Throwable t )
      {
      cat.fatal( "Serious internal error", t );
      }
    }
  return result;
  }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:47 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate won't close the session unless you ask for it

_________________
Emmanuel


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.