This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Usage of session factory and sessions  RSS feed

Posts: 16
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm fairly new to Hibernate and have just written a class DataFetcher that manages all the data fetching from the DB using Hibernate. All this fetching happens from web service methods.
I get a feeling I have done something wrong because the production server crashes on OoM Error every 5 days or so.

The service I host has 4 endpoint methods, say processDataOne(), processDataTwo() and so on.

In DataFetcher I have the following:

I have methods createSessionFactory() and destroySessionFactory():
createSessionFactory() is called at the very beginning of a service call (processDataOne()). And the destroySessionFactory() is called at the very end.

I then have methods to fetch data, fetchABC(), fetchDEF(), ... fetchXYZ()

1. I read about how hibernate implements cacheing in sessions, so now I would be modifying the above to use the same open session in multiple fetch<Data>() methods and then closing this session just before closing the session factory. Is this alright?

2. Should the sessionFactory be singleton? I also need to ensure when 1000 users are using the web service methods, this does not cause problems.
And if the sessionFactory is a singleton and inherently static, is there a way I can use the same sessionFactory between processDataOne() and processDataTwo() which are 2 different service methods.

Please suggest a good way to build this DataFetcher class and describe how to use it's methods.

Thank you!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!