resthub/spring-amqp-hessian

LazyInitializationException during serialization

Opened this issue · 2 comments

Hi,

When we serialize an object whith lazy fields, we got some lazyInitialization exceptions

16:21:04 [SimpleAsyncTaskExecutor-1] ERROR o.r.rpc.RawMessageDelegate - Exception occurs during method call
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:186) ~[hibernate-core-4.1.8.Final.jar:4.1.8.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:137) ~[hibernate-core-4.1.8.Final.jar:4.1.8.Final]
at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:242) ~[hibernate-core-4.1.8.Final.jar:4.1.8.Final]
at com.caucho.hessian.io.CollectionSerializer.writeObject(CollectionSerializer.java:96) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:421) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:293) ~[hessian-4.0.7.jar:na]
Wrapped by: java.lang.RuntimeException: could not initialize proxy - no Session
field: fr.parcours4.auth.model.InternalUser.workPlaces
at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:295) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.io.UnsafeSerializer.writeInstance(UnsafeSerializer.java:212) ~[hessian-4.0.7.jar:na]
Wrapped by: java.lang.RuntimeException: could not initialize proxy - no Session
field: fr.parcours4.auth.model.InternalUser.workPlaces
class: fr.parcours4.auth.model.InternalUser (object=User[Id: 36, Login: login1, Email: user1@test.com])
at com.caucho.hessian.io.UnsafeSerializer.writeInstance(UnsafeSerializer.java:215) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.io.UnsafeSerializer.writeObject(UnsafeSerializer.java:171) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:421) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.io.AbstractHessianOutput.writeReply(AbstractHessianOutput.java:558) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:323) ~[hessian-4.0.7.jar:na]
at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:202) ~[hessian-4.0.7.jar:na]
at org.resthub.rpc.RawMessageDelegate.createResponseBody(RawMessageDelegate.java:162) ~[spring-amqp-hessian-1.0.1-SNAPSHOT.jar:na]
at org.resthub.rpc.RawMessageDelegate.handleMessage(RawMessageDelegate.java:116) ~[spring-amqp-hessian-1.0.1-SNAPSHOT.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_09]

Jean-Sébastien

Pull Request sent using the first solution (custom hibernate serializer) :
#6