From: Brad C. <bra...@wo...> - 2002-08-31 05:13:56
|
originally i wondered whether this would work as the struts action servlet does a RequestDispatcher.forward to pass control to the resource specified by the ActionForward resulting from an Action. however, i did a quick little test, and i think your solution would work. ideally though, u would only want a session created if the processing of the request used hibernate. brad ----- Original Message ----- From: "Colin Evans" <ce...@mo...> To: <hib...@li...>; <bra...@wo...> Sent: Wednesday, August 28, 2002 6:59 AM Subject: Re: mvc & lazy loading > Hi Brad, > > I haven't tried this yet, but if I wanted to use lazy loading with Struts, I > would probably override ActionServlet and do something like this, and have > my DAO layer pull the session from the request context as needed: > > ---- > /** > * Hibernate Action Servlet > */ > public class HibernateActionServlet > extends ActionServlet > { > public void service(HttpServletRequest request, > HttpServletResponse response) > { > Session session = null; > try > { > session = factory.openSession(); > request.setAttribute("session", session); > super.service(request, response); > } > finally > { > if(session != null) session.close(); > } > } > } > ---- > > Do other frameworks allow the controller servlet to be overridden? This > probably is a fairly straightforward way to get lazy loading working. > > -Colin > > -- > Colin Evans > Mobilesys > www.mobilesys.com > |