View Full Version : Spring with Hessian and Hibernate LazyLoading

05-02-2010, 07:04 PM

During my school-project i like to have access from a Client (javaFx) to a Serverapplication (Tomcat 6) with Spring as framework. But now, on the persistence Layer i've got the problem by Loading Entity with OneToMany-Relations over my defined Services. i've try to get a Entity over Hessian call. But actually i get the error:

2010-05-02 16:23:49,548 [main] ERROR - failed to lazily initialize a collection, no session or session was closed
0org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationException(AbstractPersi stentCollection.java:380)

My Service Export in applicationcontext.xml look like this:
<bean id="customerHessianService" class="org.springframework.remoting.caucho.HessianService Exporter">
<property name="service" ref="customerService" />
<property name="serviceInterface" value="Application.Sale.Service.ICustomerService" />

The dispatcher-servlet.xml look like this:
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<prop key="/calculationBP.service">calcalutionBusinessSercvice</prop>

The Entity has a OneToMany Relation with the follow JPA Annotations:
@OneToMany(fetch = FetchType.EAGER, targetEntity = Item.class, mappedBy = "_itemHeadId", cascade = { CascadeType.REMOVE })
private Collection<Item> _headItems = new HashSet<Item>();

When i debug the Server side i can see that my Annotation - fetch=FechtType=EAGER works, i have all the child entities when i call getChilds() methode on EntityPojo. But when Hessian try to call method com.caucho.hessian.io.HessianInput.readObject() i get the "LazyInitializationException". :confused:
I don't understand why hessian makes the load of child entities twice? there are already in collection on EntityPojo or isn't it?

Could anyone say me a way to solve this problem? Thanks for Help.