• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Usage of session factory and sessions  RSS feed

 
Greenhorn
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!