|
From: Juergen H. <ju...@in...> - 2005-02-14 15:14:21
|
Hi Per, I am aware of the Hibernate docs that the Session needs to be discarded when an exception was thrown. However, I find that an overly strict statement (just like "there is no such thing as a non-transactional Session", their famous statement from their forums mid last year). Session.clear should be good enough for resetting an OSIV Session after a rollback. It's probably advisable to not use OSIV in single session mode at all if you want to avoid side effects completely. (Closing the Session and opening a new one during OSIV doesn't really add value here.) Have you considered using OpenSessionInViewFilter in "deferred close mode", that is, with the "singleSession" flag turned off? In that case, each transaction will use its own Hibernate Session, but all of those Sessions will be kept open until view rendering has completed. Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Per Olesen Sent: Monday, February 14, 2005 3:54 PM To: spr...@li... Cc: James Cook Subject: Re: [Springframework-developer] Potentialt dangerous hibernate Session reuse Hi, On Monday 14 February 2005 15:06, you wrote: > It's good that you are considering the exceptional circumstances when using > Hibernate. OpenSessionInView (OSIV) is certainly seductive because of its > ability to support lazy-loading while the view is being rendered. Once you > go beyond the realm of the simple application and have to support > exceptional circumstances, OSIV can be very problematic. > > I think you will continue to run into other use cases where OSIV causes > undesirable behavior, as we did. Eventually, we changed our approach and > went with a service layer (in the spirit of an EJB Stateless Session Bean) > that clearly demarcates the Hibernate Session and database transactions. It > has made our life much easier and more deterministic. The only drawback is > that the service layer is responsible for eager loading the lazy-loaded > collections prior to the view rendering. Your comments hit right on the considerations we had on using it or not. It also seems that there are different thoughts on the spring lists about if it is good or bad. Maybe we should provide some more documentation/information in spring with considerations on if you should be using it or not? I think many folks start using it without realizing the consequences. I would be glad to start it with my thoughts on the subject! Personally, I think there is room for it in some projects, mine included :-) We experience fast and seamless development of new view pages, when we do not have to think about precisely which parts of the model, we need to eager load. But, I was more thinking about if the actual solution of spring using session.clear() is safe enough, or if I should keep going with my own solution here? Or if maybe spring should take another solution? Any thoughts on that? Regards, Per -- Per Olesen @ Nordija A/S - www.nordija.com - main#: +45 70 20 25 10 email: po...@no... - cell#: +45 23 38 95 81 ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |