-->
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: help on realeasing a hibernate session
PostPosted: Tue May 25, 2010 9:27 pm 
Newbie

Joined: Tue May 25, 2010 9:15 pm
Posts: 1
Hi All,

Im really new to hibernate, its been a week now on lingering through the codes that im handling now. im just using a lower version, i think its 1.1.x

right now im cleaning the codes as there are some hibernate sessions which are not closed
once a query or update is called. My task was to clear them up which consumes memory after using them.

Here is a sample of the current code:

public java.util.List findBook()
{
return findBook(getSession());
}



the solution i though off was

public java.util.List findBook()
{
Session sess = null;
try
{
sess = getSession();
return findBook(sess);
}
finally
{
SessionFactoryUtils.closeSessionIfNecessary(sess, getSessionFactory());
}
}


I like to ask any comments if what ive done is correct. or should do something else.
many thanks.


Top
 Profile  
 
 Post subject: Re: help on realeasing a hibernate session
PostPosted: Wed May 26, 2010 5:46 am 
Newbie

Joined: Wed May 26, 2010 5:02 am
Posts: 4
Hi,

I don't understand what do you want. In normal way, the session closing is responsibility of session opener. So

Code:
lSess = HibernateUtil.getSessionFactory().openSession()
try
...
finally
{
  lSess.close();
  ...
}

For example: If you close the session in your entity class, that means this class can not member of transaction, because after the calling you close the session.

I think the auto-close class is not god way.
Feri


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.