struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Axel Stahlhut <astahl...@neusta.de>
Subject Re: OT: Hibernate Session to User Session
Date Sun, 09 May 2004 00:22:12 GMT
Riyad Kalla wrote:

>I was reading in the Hibernate forums that when you have a WebApp > DAO
>  
>
>>Hibernate > DB design, and you open/close each Hibernate session at
>>    
>>
>every single DAO method call (what I do now) its actually quite
>expensive, and is suggested that you attempt to maintain a Hibernate
>Session in conjunction with a user Session to increase performance.
>
>I had a question for anyone that has done this (without using
>SpringFramework). My gut-reaction to this was to add a
>HttpSessionListener to my webapp that created and stored a Hibernate
>session in the user's session, and then close it when the Session
>expired... will this not work? Anyone else have a good solution for
>this?
>
>TIA,
>Riyad
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>
Hi.

Thisis not a Hibernate forum... Anyway: If you read the docs, you will 
find good practice not to hold a long during hibernate session. You 
would get problems with synchronisation and consistent hibernate session 
states, furthermore this would result in too many open sessions. (Good 
point for denial of service-attack...)
I prefer using hibernate sessions hold in a ThreadLocal, which is really 
nice because you do not have to get HibernmateSession through all of 
your method signatures. The Session is opened at beginning of the 
Request and closed at the end. I close it in a ServletFilter, so i can 
do within Srtruts whatever i want (declarative Exception handling...) 
and i can be sure it is always closed. This way i also can track the max 
parallel open Hibernate Sessions, which tells a lot over server load.

Regards Axel

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message