Hi,
i have problem with Lazy loading of collections (List).
I have POJO object - class A, this object has property - Lists of objects B.
Code:
@OneToMany(mappedBy = "objectB", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "fk_b_id")
private List<B> objectsB;
i use LAZY loading for this object.
so, i try load object A by id:
A objectA = objectAManager.getA(id);
in get function I use: getHibernateTemplate().get
how can I load all collections for object A.
after JSP code:
Code:
<c:forEach items="${A.objectsB}" var="objectA" varStatus="current">
</c:forEach>
this error message is displayed:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.freightservice.model.A.ObjectsB, no session or session was closed
i use interceptor:
Code:
<beans>
<bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="singleSession">
<value>false</value>
</property>
</bean>
</beans>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
</list>
</property>
<property name="mappings">
....
</property>
</bean>
thanks!
Ivan