The problem with this is that it does not address the issue of reattaching detached objects to the currently-open session. Since it is natural in Tapestry to instantiate an object, use it in a page, and then to persist the (potentially) changed object, the object must first be reattached to the Hibernate session. Even if the object is not persisted, if it contains lazy collection references it is necessary to reattach the object in order for the collection to be properly initialized.
The only reliable solution I have found is to use Spring's OpenSessionInView filter with singleSession=true, and then to explicitly reattach objects in pageBeginRender(). I use a custom HibernateService class which implements methods for attach(), evict(), and merge(). The attach() method actually does a getSession().lock(object, LockMode.NONE), but it handles NonUniqueObjectExceptions which will commonly be thrown when using lazy collections if one of the collection objects happens to already exist in the session. Shawn Quoting Andreas Andreou <[EMAIL PROTECTED]>: > Regarding to not using servlet filters for the OpenSessionInView > approach, I can confirm that other approaches work! > First of all, > i've always used the HibernateUtil class posted in hibernate forums > (and maybe also included in Hibernate in Action) that stores and > gets > session and transaction objects in thread local variables. > > So, opening a hibernate session is never a problem (whichever method > first uses one, creates it) and so it only remains the issue of > closing it > somewhere. > > I haven't tried the cleanupAfterRequest() of Engine approach. > Instead i've always extended the > pageEndRender(PageEvent event) > in a BasePage (that all my pages extend) and there I just do: > > super.pageEndRender(event); > HibernateUtil.closeSession(); > > The nice thing is that this closeSession() never complains, no > matter > if no session is found, or if it has already been closed. > > Anyway, I can post the HibernateUtil class here if you want to... > Andreas > > Alejandro Scandroli wrote: > > >Henry Chen wrote: > > > > > >>I have been searching around desperately for solution of handling > >>lazy-loading database objects in tapestry. I configured > >>OpenSessionInViewFilter for Tapestry pages. It worked for some > cases > >>but not all. For example, in the table component, the first page > was > >>good, but when I selected other pages, it gave me the > >>LazyInitialization exception - owning session was closed. Is there > any > >>way around it now? Thanks a lot! > >> > >> > > > >Hi , I'm having the same problem on Trails. > >This quote may help. > > > >quote form Open Session in View discussion on Hibernate site. > ><quote> > >Open Session pattern and Tapestry web framework > >24 Mar 2004, 19:27 wassup > > > >If you develop your application with Tapestry framework it is > better > >do not use Servlet Filters to manage request cycle. More preferable > to > >override setupForRequest() and cleanupAfterRequest() of Engine > >class. > ></quote> > > > >I have no time to try this. > >Please let me know if it works for you, or if you find another > workaround. > > > >Saludos. > >Alejandro. > > > >PD:- please, excuse my English. > > > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: > [EMAIL PROTECTED] > >For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
