• 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

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?
reply
    Bookmark Topic Watch Topic
  • New Topic