From: Keats <ke...@xa...> - 2004-03-04 17:43:08
|
One small correction on my previous post. You'll probably want to store and retrieve the Hibernate Session using the context rather than an instance variable (very bad idea -- not thread-safe). E.g., public void destroyContext (WebContext wc) { Session hsess = (Session)wc.get("hsess"); if (hsess != null) hsess.close(); } Keats ----- Original Message ----- From: "Keats" <ke...@xa...> To: <web...@li...> Sent: Thursday, March 04, 2004 12:08 PM Subject: Re: [WebMacro-user] Lazy loading when using Webmacro with Hibernate > WMServlet has a method called destroyContext() that was created for exactly > this kind of thing. Just override the method and do any cleanup that you > need to happen after the request is handled, like: > > public void destroyContext (WebContext wc) > { > hibernateSession.close(); > } > > This will get called by the doRequest() method after the handle() method > finishes. > > Hope this helps. > > Keats > ----- Original Message ----- > From: "c k" <woo...@ho...> > To: <web...@li...> > Sent: Wednesday, March 03, 2004 7:29 PM > Subject: [WebMacro-user] Lazy loading when using Webmacro with Hibernate > > > > I create servlets which extend WMServlet. In the handle() method, I put > > POJOs fetched from Hibenate session into Webmacro context and just return > > to let Webmacro render the page. But it reports "lazy loading problem, > > session closed". So how can I close the Hibernate session after the whole > > page has been rendered, override certain method in WMServlet or some other > > way around? I just don't know where to put Hibernate's session.close() to > > prevent lazy loading problems. > > > > Any help is appreciated. > > > > Jim Lee > > > |