From: Mark W. <mor...@SM...> - 2002-12-21 01:37:20
|
Christian Bauer wrote: >While I'm at it: Another rework, or at least a discussion about it, for >2.0 would be the automatic reconnect of Sessions. You once mentioned >that in a forum post, but didn't like it. > >My two cents: > >If you've learned the basic concepts of O/R mapping, it's easy to produce >a real, working and maintainable two-tiered application with Hibernate. > >Just use lazy collections and disconnect/reconnect the Session which is >stored in the HttpSession. At least for web applications, that is. If >you don't require the lazy loaded collection in a Servlet call or JSP, >you could even just close it and reopen it at the next call. > >In a three-tiered architecture, the recommended approach we currently >propagate is to just open new Sessions and close them with each >transaction. Some people realized that their JSP pages at the top of the >system can also start transactions (by calling transactional methods on >the Business Facade) and therefore open/close Hibernate Sessions in the >Persistence Layer somewhere further down in the system. > >They immediately face the problem of lazy loaded collections: Loading an >object at the "top" of the JSP page (results in open/retrieval/close or >reconnect/retrieval/disconnect of a Hibernate Session) and using the >accessors further "down" in the JSP will fail. So they have to either > >a) Delay the closing of the Session until the JSP is rendered >b) Delay the disconnection of the Session until the JSP is rendered > >Of course this can't happen in the JSP itself, the ViewController (the >handler of Views) should somehow send a notify which will magically >close/disconnect the Hibernate Session after the read and the whole >rendering is finished. > Have you considered using a filter to close the Session after everything is rendered? -Mark |