|
From: Colin S. <col...@ex...> - 2003-12-09 14:23:31
|
jürgen höller [werk3AT] wrote: >Everybody, > >I've reworked quite significant parts in the last couple of days, and also added a few new features: > >... > >- I've added support for the "Open Session in View" pattern with Hibernate: OpenSessionInViewInterceptor is a HandlerInterceptor for Spring's web MVC, OpenSessionInViewFilter a generic Servlet 2.3 Filter. Both can simply be used together with HibernateTransactionManager or JtaTransactionManager: The latter will automatically detect the pre-bound Sessions and leave their lifecycle management to the original binder. In the course of implementing OpenSessionInViewFilter, I've also added generic Filter base classes, namely GenericFilterBean and OncePerRequestFilter. Those classes are now also used for MultipartFilter. > > > Jürgen, While I know people are always asking for the Open Session in View pattern support, I personally think it is a pretty dangerous pattern to use. As per the Hibernate docs, http://www.hibernate.org/hib_docs/reference/html/manipulating-data.html#manipulating-data-s13-4 if Session throws an exception, the Session should be closed and discarded, as it will be inconsistent. The Open Session in View pattern will work ok if the view code ensures that once a Hibernate exception is handled no more db related code is used, but since the session handling is above all the other code, it does not enforce this in any way. In fact, if the view code is calling down to some service code that does the db access itself, the view code may not even know that db access is being done. At a minimum, I recommend we annotate the Javadocs for these classes with a warning about this aspect... Regards, Colin |