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):
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 url mappings, so reading the docs for Spring 3, I'm using this in my servlet-context.xml:
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<!-- <property name="order" value="2" /> -->
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptorInst" />
</list>
</property>
</bean>
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?