This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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!
 
no wonder he is so sad, he hasn't seen this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!