• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Hibernate Session Best Practice

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys. For a web application how many hibernate session should be opened for a one web user session? So is it like?

1 User Session = 1 Hibernate Session

How would I know then on when to close a hibernate session if a user just abandoned the application without properly logging out to invalidate all sessions?
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what database resources the user will access and how they are mapped.
In the simple case, with one database, one Session is what you need, and how to open and close it is decided in the web or business tier of the application.
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is the httpsession automatically attached to a hibernate session? So if I invalidate a httpsession, so does the hibernate session?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer your question...

No once the http session is invalidated it will NOT close your hibernate session.

Also, last time I checked the Hibernate team was suggesting using one hibernate session per request. (Not per http session.)

I believe it is called the one hibernate session per request pattern. You should be able to find information about it (the pattern) on hibernates website.

Best of Luck.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic