• 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

Usage of session factory and sessions

 
Greenhorn
Posts: 16
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
We should throw him a surprise party. It will cheer him up. We can use 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