|
|
How do I get sure that OpenSessionInViewInterceptor is used for requests?
Hello,
I had the (in)famous problem with hibernate and lazy loading when views are rendered.... As many say, the only two solutions are:
- Make the method transactional (and this is not always desiderable)
- Use OpenSessionInViewInterceptor.
The latter is preferable IMO. Anyway I'm not sure if this interceptor is firing at all (in fact I get the same Lazy loading exception and nothing changes):Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: it.jsoftware.jacciseweb.beans.Listino.prodotti, no session or session was closed
I'm using simple annotation based ucl mappings, so reading the docs for Spring 3, I'm using this in my servlet-context.xml:Code:
lt;bean id=quot;handlerMappingquot;
class=quot;org..web.servlet.mvc.annotation.DefaultAnnotationHandlerMappingquot;gt;
lt;!-- lt;property name=quot;orderquot; value=quot;2quot; /gt; --gt;
lt;property name=quot;interceptorsquot;gt;
lt;listgt;
lt;ref bean=quot;openSessionInViewInterceptorInstquot; /gt;
lt;/listgt;
lt;/propertygt;
lt;/beangt;
Which should make the trick. But it is not working and I get the exception. How do I make sure my interceptor is firing? How do I solve this?
That should work. Can you post your full configuration xml file?
That didn't work. The solution is this:Code:
lt;mvc:interceptorsgt; lt;bean class=quot;org..orm.hibernate3.support.OpenSessionInViewInterceptorquot;gt; lt;property name=quot;sessionFactoryquot;gt;lt;ref local=quot;mySessionFactoryquot; /gt; lt;/propertygt; lt;/beangt;
lt;/mvc:interceptorsgt;What didn't work?
I asked you to post your full xml configuration since you did not show the bean definition of quot;openSessionInViewInterceptorInstquot;. You can configure the interceptors the other way as well if you have your interceptor bean definition setup correctly. |
|