[mule-user] How can we get an hibernate session interceptor configured in Mule?

4 views
Skip to first unread message

Slyge

unread,
Jan 3, 2008, 11:24:59 AM1/3/08
to us...@mule.codehaus.org

How can we get an hibernate session interceptor configured in Mule?

Because when the object is serialized, we get a LazyException (session
closed)

Thanks


--
View this message in context: http://www.nabble.com/How-can-we-get-an-hibernate-session-interceptor-configured-in-Mule--tp14600208p14600208.html
Sent from the Mule - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Andrew Perepelytsya

unread,
Jan 3, 2008, 11:32:44 AM1/3/08
to us...@mule.codehaus.org
Isn't it configured on the Hibernate Session Factory? What object is serialized that causes an exception?

Andrew

Slyge

unread,
Jan 4, 2008, 10:41:32 AM1/4/08
to us...@mule.codehaus.org

In fact, we invoke a webservice method from mule client then an hibernate
session is opened by spring on the target server, all SQL requests are
executed and then session is closed. Next, the result is serialized to be
sent as message payload to the MuleClient. But when doing that, a lazy
exception occured because the session is already closed. We don't know how
to tell mule to keep the hibernate session opened.

Here is the stack trace:

2008-01-04 16:30:56,427 INFO [STDOUT] 16:30:56,421 ERROR
[LazyInitializationException] Failed to lazily initialize a collection - no
session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a
collection - no session or session was closed
at
net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
at
net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.size(Set.java:106)
at
org.apache.axis.encoding.ser.ArraySerializer.serialize(ArraySerializer.java:221)
at
org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1504)
at
org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980)
at
org.apache.axis.encoding.SerializationContext.outputMultiRefs(SerializationContext.java:1055)
at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:145)
at
org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478)
at
org.apache.axis.message.MessageElement.output(MessageElement.java:1208)
at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:315)
at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269)
at org.apache.axis.SOAPPart.saveChanges(SOAPPart.java:530)
at
org.apache.axis.attachments.AttachmentsImpl.getAttachmentCount(AttachmentsImpl.java:554)
at org.apache.axis.Message.getContentType(Message.java:486)
at
org.mule.providers.soap.axis.AxisServiceComponent.doPost(AxisServiceComponent.java:612)
at
org.mule.providers.soap.axis.AxisServiceComponent.onCall(AxisServiceComponent.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.mule.impl.model.resolvers.DynamicEntryPoint.invokeMethod(DynamicEntryPoint.java:312)
at
org.mule.impl.model.resolvers.DynamicEntryPoint.invoke(DynamicEntryPoint.java:259)
at
org.mule.impl.DefaultLifecycleAdapter.intercept(DefaultLifecycleAdapter.java:194)
at
org.mule.impl.InterceptorsInvoker.execute(InterceptorsInvoker.java:47)
at
org.mule.interceptors.EnvelopeInterceptor.intercept(EnvelopeInterceptor.java:44)
at
org.mule.impl.InterceptorsInvoker.execute(InterceptorsInvoker.java:47)
at
org.mule.impl.model.DefaultMuleProxy.onCall(DefaultMuleProxy.java:258)
at
org.mule.impl.model.seda.SedaComponent.doSend(SedaComponent.java:393)
at
org.mule.impl.model.AbstractComponent.sendEvent(AbstractComponent.java:418)
at org.mule.impl.MuleSession.sendEvent(MuleSession.java:349)
at
org.mule.routing.inbound.InboundRouterCollection.send(InboundRouterCollection.java:197)
at
org.mule.routing.inbound.InboundRouterCollection.route(InboundRouterCollection.java:163)
at
org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:581)
at
org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:322)
at
org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:269)
at
org.mule.providers.http.HttpMessageReceiver$HttpWorker.doGetOrPost(HttpMessageReceiver.java:233)
at
org.mule.providers.http.HttpMessageReceiver$HttpWorker.processRequest(HttpMessageReceiver.java:177)
at
org.mule.providers.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:150)
at org.mule.impl.work.WorkerContext.run(WorkerContext.java:310)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:987)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:528)
at java.lang.Thread.run(Thread.java:595)

--
View this message in context: http://www.nabble.com/How-can-we-get-an-hibernate-session-interceptor-configured-in-Mule--tp14600208p14618944.html

Andrew Perepelytsya

unread,
Jan 4, 2008, 10:46:57 AM1/4/08
to us...@mule.codehaus.org
I'm not sure this would ever work. Are you telling you are trying to send back a Hibernate-enhanced object? Ehh? In this case this smells so badly...

Slyge

unread,
Jan 4, 2008, 7:01:17 PM1/4/08
to us...@mule.codehaus.org

In fact, we had a web application (a war file) with a jar library embedded
that makes some work on Database.

We want to put this library into mule by exposing the methods of dao as
webservices (and then the client would invoke webservices). But when we
invoke these methods we have a lazy exceptions (because some collections are
lazy loaded). Perhaps this is not the right approach? what should we do?

thanks for your answers.

--
View this message in context: http://www.nabble.com/How-can-we-get-an-hibernate-session-interceptor-configured-in-Mule--tp14600208p14627547.html

Andrew Perepelytsya

unread,
Jan 4, 2008, 7:09:52 PM1/4/08
to us...@mule.codehaus.org
You should go to the Hibernate applications design forums. My recommendation (not the only solution possible, but at least guaranteed to always work and cleanly) is to introduce a dto layer (it's not that important if it's technically a dto or something else). The point is that Hibernate enhances your domain objects and they can't be  easily transferred remotely unless the other side has the same Hibernate jar available at runtime as well.

The lazy loading exception is a classic issue, in this case axis probably tries to inspect your complete object graph. Not sure adding extra Hibernate.initialize() calls would help (due to performance implications of eagerly fetching all collections).

Really, it's not an error, rather a design decision has to be made.

Andrew

Slyge

unread,
Jan 5, 2008, 5:06:22 AM1/5/08
to us...@mule.codehaus.org

ok I will look for dto, I also think it's a problem of design.

Thanks a lot for your answers.

--
View this message in context: http://www.nabble.com/How-can-we-get-an-hibernate-session-interceptor-configured-in-Mule--tp14600208p14631579.html

John D'Emic

unread,
Jan 5, 2008, 3:42:47 PM1/5/08
to us...@mule.codehaus.org
is there a reason you can't disable lazy loading for this class/collection?

--
John D'Emic



Rob Sessink

unread,
Jan 7, 2008, 3:26:53 AM1/7/08
to us...@mule.codehaus.org
I have dealt also with this problem. You get the
LazyInitializationException
because you try to access object in the hibernate object graph which are
not
yet initialised. Hibernate will initialise these object when accessed,
in your
situation this happens when they get serialized (probably by an Outbound

transformer) When this tranformation occurs your Session is already
closed.

I also thought about implementing an Hibernate Session Interceptor but
this
will not work correctly because of the mule message flow: See the image
under "The Programming Model" in

http://mule.mulesource.org/display/MULE/Programmers+Guide

Because an "Outbound Transformer" comes after the "Envelope
interceptor",
which will close the session,you will still run into
LazyInitializationException exception when trying to access not
initialized
parts of the object graph.

The solution i used was to set the hibernate mappings for some
associated
objects to "lazy=false"

See
http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html#
performance-fetching-lazy

But be careful with "lazy=false" setting that you won't query to much.
Another solution would be to create an dto when the Session is still
active. Your using spring so it's worth to look at doing the hibernate
session/transaction management by using spring aop. With this you'll
have finer control over your Session lifetime

Regards Rob

> -----Oorspronkelijk bericht-----
> Van: Slyge [mailto:slyg...@yahoo.fr]
> Verzonden: zaterdag 5 januari 2008 11:06
> Aan: us...@mule.codehaus.org
> Onderwerp: Re: [mule-user] How can we get an hibernate

> session interceptor configured in Mule?
>
>

Reply all
Reply to author
Forward
0 new messages