• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Hibernate issue with `SessionFactory`

 
Ranch Hand
Posts: 507
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all please note I have posted the below question in Stackoverflow and I have one answer there, but I am not sure about it because it seems like the member who answered also not much sure about his answer. Below is my question.

I am having a JSP, Servlet (Pure JSP, Servlet) application where it uses `Hibernate`. Below is a `Hibernate` implementation class for a one table.

DesignationImpl.java




Below is the service class which calls to the above class.

DesignationService .java




And the servlets call them like below.



As you can see, there is a bad thing happening there, that is, the servlets are creating new `SessionFactory` instances every time it executes.I am having `Driver#Connect` issues and I guess this might be the reason for it.

I read stackoverflow posts and some seems to be suggesting the use of only one `SessionFactory` for the entire application. If it is suitable, then how can I do it? Maybe make a singleton class like below and use it in my implementation classes?



But then what about threads? Servlets are multi threaded isn't it?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic