• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Management for Hibernate.

 
Vishwas Shashidhar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am developing a web application which uses Hibernate. And i am storing the "Hibernate Session" object in a "Http Session" object. However, i have come across a problem when there are multiple users who update the data. In that case, since the "Hibernate Session" is in "Http Session", data will get updated only for the user who has updated the data unless the other users log out and a new session is created for them.

I am a bit stuck here. I thought of storing the "Hibernate Session" in the application context instead of the session context. However, i have a feeling that the data might become stale with just one hibernate session for the entire application. So, please help me out and guide me through. Will be really grateful.


Regards,
Vishwas
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want all user's to share one Hibernate session? Sounds like a bottleneck to me; and will you not be risking lost updates in the first level cache?
 
Deriko Prata
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Paul, why are you trying to do this, i never heard of similar approach. Why don't you try opening hibernate session in a servlet filter, hence, applying hibernate Open session in View pattern? This way you guarantee one hibernate session per thread and not for the entire application. Also you can have some benefits as using lazy objects in your view, since your view is rendered before closing hibernate session. Note that this pattern only works in applications executing in a single jvm.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic