Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Session Best Practice

 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • 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?
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Nathan Hook
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic