• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help on releasing hibernate session

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does SessionFactoryUtils.closeSessionIfNecessary(sess, getSessionFactory()); do? I can't remember the API for v1.1, but can't you just call session.close()?
 
Casper Serrano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the link that im reading..

http://static.springsource.org/spring/docs/1.1.x/api/org/springframework/orm/hibernate/SessionFactoryUtils.html

from what i understand.

when i use getSession().. i obtain an instance of the Session from SessionFactory.

so i just use SessionFactoryUtils then call closeSessionIfNecessary() method.

thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using such a crazy-old Spring?! That's circa... 2004?
 
Casper Serrano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my apologies.

this is the version my company is using.
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic