I read on the hibernate site:
When to create and when to close a session depending on your framework (struts, spring, etc). First I was opening the session for each request call inside the Struts actions, but the session would close prematurely by the time the JSP is executed. Then I tried a Servlet Listener pattern as prescribed in the book Hibernate in Action (Christian Bauer, Gavin King - Manning). That would cause trouble as well because the session would remain open and Tiles insert would cause multiple session to open before others were closed.
My last resort was to extend Struts Actions servlet and wrap the processRequest() with the open/close call for the session and that seems to be very stable. (
http://www.hibernate.org/113.html)
This seems to suggest that the hibernatefilter basically is not workable in many frameworks. Sitemesh and Tiles are pretty common. I'm a little surprised that such a crucial aspect of implementing Hibernate is clouded in uncertainty. To tell you the truth, I'm totally confused now, but I can't believe it could be this difficult. So, it must be me :-)
Can anybody enlighten me on the definitive way to use the open session in view in a layered application using sitemesh or tiles? Let's assume that objects will have lazy collection references and that those collections will be accessed in the jsp as well.
Thanks,
Marc