You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Steve S <tr...@gmail.com> on 2007/08/21 22:36:03 UTC

Returning Hibernate detached objects in Axis2

Has anyone tried to return a Hibernate detached object in an Axis2 web
service? I have an object with lazy-loaded collections of objects. When I
try to call the web service, I get a LazyInitializationException because the
serializer (Axiom? StAX?) is trying to iterate over the collection. What I
need is a way to skip the attribute if it is a PersistentSet that hasn't
been initialized.  I suspect that the actual coding is pretty simple, the
trick is figuring out where to put it, and how to get Axis to use it.

Does anyone have any ideas?

Thanks,

Steve

Re: Returning Hibernate detached objects in Axis2

Posted by robert lazarski <ro...@gmail.com>.
I typically just use the getters to populate xml via databinding,
though you may have luck with JiBX - look at those docs on its main
site as they talk a bit about hibernate.

HTH,
Robert

On 8/21/07, Steve S <tr...@gmail.com> wrote:
> Has anyone tried to return a Hibernate detached object in an Axis2 web
> service? I have an object with lazy-loaded collections of objects. When I
> try to call the web service, I get a LazyInitializationException because the
> serializer (Axiom? StAX?) is trying to iterate over the collection. What I
> need is a way to skip the attribute if it is a PersistentSet that hasn't
> been initialized.  I suspect that the actual coding is pretty simple, the
> trick is figuring out where to put it, and how to get Axis to use it.
>
> Does anyone have any ideas?
>
> Thanks,
>
> Steve
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Returning Hibernate detached objects in Axis2

Posted by robert lazarski <ro...@gmail.com>.
You still seem to talking about a client / service invokation across
jvm's, and lazy loaded hibernate objects don't work like that. You may
be able to get the effect you're looking for with pagination. Or slice
and dice your objects in the same transaction - but that's not lazy
loading. Or use some type of rich client framework like flex that
supports web services. Or look at something along the lines of JSON in
axis2.

So I see lots of options but lazy loading doesn't seem to be the right
fit. However, another reply mentioned spring's OSIV which is the
standard way of using lazy objects in a gui - though how that'd work
in axis2 client / service invokation is the dragon you'd have to slay.
 I'd be curious to see how it'd work.

HTH,
Robert

On 8/22/07, Steve S <tr...@gmail.com> wrote:
> I can think of a use case.  Let's say you have a batch process that slices
> and dices data.  You want to build a GUI to maintain certain master setup
> data. Since the batch process runs in a single session, you want to be able
> to use Hibernate's capabilities to slice and dice that data - in particular,
> you build objects with children, then just save the object and let Hibernate
> do the rest.  But you don't want the object graph returned to the GUI
> because you are only working with a small part of the object graph.
>
> Web services are being used as the transport between the GUI and the server.
>
> I may need to re-think my object definitions.  It may be possible to solve
> my problem by careful consideration of what I am linking and what I'm not.
>
> I am rather supprised that there isn't more discussion about dealing with
> Hibernate detached objects in Axis - at least I havent found a good site
> yet.
>
> Steve
>
>
>
> > <snip>
> >
> > Lazy loading hibernate AFAIK doesn't work across JVM's so I'm failing
> > to see a use case for it in web services. Using hibernate interceptors
> > or perhaps eventing would be one way to know if the collection was
> > populated - but that's pretty off topic for this list.
> >
> > There are ways to prevent axiom from loading everything in memory via
> > streaming it, while still getting the graph into the xml. Search the
> > list if interested as the topic comes up sometimes.
> >
> > HTH,
> > Robert
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Returning Hibernate detached objects in Axis2

Posted by Steve S <tr...@gmail.com>.
I can think of a use case.  Let's say you have a batch process that slices
and dices data.  You want to build a GUI to maintain certain master setup
data. Since the batch process runs in a single session, you want to be able
to use Hibernate's capabilities to slice and dice that data - in particular,
you build objects with children, then just save the object and let Hibernate
do the rest.  But you don't want the object graph returned to the GUI
because you are only working with a small part of the object graph.

Web services are being used as the transport between the GUI and the server.

I may need to re-think my object definitions.  It may be possible to solve
my problem by careful consideration of what I am linking and what I'm not.

I am rather supprised that there isn't more discussion about dealing with
Hibernate detached objects in Axis - at least I havent found a good site
yet.

Steve



> <snip>
>
> Lazy loading hibernate AFAIK doesn't work across JVM's so I'm failing
> to see a use case for it in web services. Using hibernate interceptors
> or perhaps eventing would be one way to know if the collection was
> populated - but that's pretty off topic for this list.
>
> There are ways to prevent axiom from loading everything in memory via
> streaming it, while still getting the graph into the xml. Search the
> list if interested as the topic comes up sometimes.
>
> HTH,
> Robert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: Returning Hibernate detached objects in Axis2

Posted by robert lazarski <ro...@gmail.com>.
On 8/22/07, Steve S <tr...@gmail.com> wrote:
> Keeping the session open and turning off lazy loading both have the same
> undesirable side effect of loading the entire object graph before returning
> a result.  This can result in a very large amount of data being returned.
> What I was really hoping for was a way to change the way the XML was
> generated so that it took Hibernate Collections into mind so that I can
> check if it is initialized or not before descending into the collection.
>

<snip>

Lazy loading hibernate AFAIK doesn't work across JVM's so I'm failing
to see a use case for it in web services. Using hibernate interceptors
or perhaps eventing would be one way to know if the collection was
populated - but that's pretty off topic for this list.

There are ways to prevent axiom from loading everything in memory via
streaming it, while still getting the graph into the xml. Search the
list if interested as the topic comes up sometimes.

HTH,
Robert

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: Returning Hibernate detached objects in Axis2

Posted by Steve S <tr...@gmail.com>.
Keeping the session open and turning off lazy loading both have the same
undesirable side effect of loading the entire object graph before returning
a result.  This can result in a very large amount of data being returned.
What I was really hoping for was a way to change the way the XML was
generated so that it took Hibernate Collections into mind so that I can
check if it is initialized or not before descending into the collection.

I could always sever the relationships between parents and children so there
would be no collections at all, but that makes my server side code a lot
more messy because I'll have to keep going to the database myself to get
children instead of just passing a parent object around and going to the
collection of children.

Isn't the ability to relate objects together one of the advantages of
Hibernate?

I may wind up having to do this anyway because even if I solve the hibernate
issue, there is still the circular link issue - parents have children, each
child points to its parent.

The journey continues }:-)

Steve

On 8/22/07, robert lazarski <ro...@gmail.com> wrote:
>
> IIRC the other option is to turn lazy off so your collection aren't
> proxied, which may make sense in a web service environment where
> you'll probably need to gather all the objects anyways.
>
> Hmm, wasn't aware you could use OSIV with axis2.
>
> HTH,
> Robert
>
> On 8/22/07, Michael.Davis@servicecanada.gc.ca
> <Mi...@servicecanada.gc.ca> wrote:
> >
> >
> > Hi,
> >
> > I'm doing just that. I've got a web application that has the axis2
> > libraries. It provides a web service as well as a web application that
> > maintains a database. I use the Spring library to provide both the web
> > service and the application with a DAO that interfaces with Hibernate. I
> use
> > Spring's OpenSessionInViewFilter to keep the session open until the
> final
> > result is rendered, whether it's axis or a jsp doing the rendering.
> >
> > If you don't want to use spring, you can write your own servlet filter
> that
> > opens a Hibernate session coming in and closes it going out.
> >
> > Michael Davis
> > from sunny Ottawa
> >
> >
> > -----Original Message-----
> > From: Steve S [mailto:triviaguy@gmail.com]
> > Sent: Tuesday, August 21, 2007 4:36 PM
> > To: axis-user@ws.apache.org
> > Subject: Returning Hibernate detached objects in Axis2
> >
> >
> > Has anyone tried to return a Hibernate detached object in an Axis2 web
> > service? I have an object with lazy-loaded collections of objects. When
> I
> > try to call the web service, I get a LazyInitializationException because
> the
> > serializer (Axiom? StAX?) is trying to iterate over the collection. What
> I
> > need is a way to skip the attribute if it is a PersistentSet that hasn't
> > been initialized.  I suspect that the actual coding is pretty simple,
> the
> > trick is figuring out where to put it, and how to get Axis to use it.
> >
> > Does anyone have any ideas?
> >
> > Thanks,
> >
> > Steve
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: Returning Hibernate detached objects in Axis2

Posted by robert lazarski <ro...@gmail.com>.
IIRC the other option is to turn lazy off so your collection aren't
proxied, which may make sense in a web service environment where
you'll probably need to gather all the objects anyways.

Hmm, wasn't aware you could use OSIV with axis2.

HTH,
Robert

On 8/22/07, Michael.Davis@servicecanada.gc.ca
<Mi...@servicecanada.gc.ca> wrote:
>
>
> Hi,
>
> I'm doing just that. I've got a web application that has the axis2
> libraries. It provides a web service as well as a web application that
> maintains a database. I use the Spring library to provide both the web
> service and the application with a DAO that interfaces with Hibernate. I use
> Spring's OpenSessionInViewFilter to keep the session open until the final
> result is rendered, whether it's axis or a jsp doing the rendering.
>
> If you don't want to use spring, you can write your own servlet filter that
> opens a Hibernate session coming in and closes it going out.
>
> Michael Davis
> from sunny Ottawa
>
>
> -----Original Message-----
> From: Steve S [mailto:triviaguy@gmail.com]
> Sent: Tuesday, August 21, 2007 4:36 PM
> To: axis-user@ws.apache.org
> Subject: Returning Hibernate detached objects in Axis2
>
>
> Has anyone tried to return a Hibernate detached object in an Axis2 web
> service? I have an object with lazy-loaded collections of objects. When I
> try to call the web service, I get a LazyInitializationException because the
> serializer (Axiom? StAX?) is trying to iterate over the collection. What I
> need is a way to skip the attribute if it is a PersistentSet that hasn't
> been initialized.  I suspect that the actual coding is pretty simple, the
> trick is figuring out where to put it, and how to get Axis to use it.
>
> Does anyone have any ideas?
>
> Thanks,
>
> Steve
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: Returning Hibernate detached objects in Axis2

Posted by Mi...@servicecanada.gc.ca.
Hi,
 
I'm doing just that. I've got a web application that has the axis2 libraries. It provides a web service as well as a web application that maintains a database. I use the Spring library to provide both the web service and the application with a DAO that interfaces with Hibernate. I use Spring's OpenSessionInViewFilter to keep the session open until the final result is rendered, whether it's axis or a jsp doing the rendering.
 
If you don't want to use spring, you can write your own servlet filter that opens a Hibernate session coming in and closes it going out.
 
Michael Davis
from sunny Ottawa
 

-----Original Message-----
From: Steve S [mailto:triviaguy@gmail.com]
Sent: Tuesday, August 21, 2007 4:36 PM
To: axis-user@ws.apache.org
Subject: Returning Hibernate detached objects in Axis2


Has anyone tried to return a Hibernate detached object in an Axis2 web service? I have an object with lazy-loaded collections of objects. When I try to call the web service, I get a LazyInitializationException because the serializer (Axiom? StAX?) is trying to iterate over the collection. What I need is a way to skip the attribute if it is a PersistentSet that hasn't been initialized.  I suspect that the actual coding is pretty simple, the trick is figuring out where to put it, and how to get Axis to use it. 
 
Does anyone have any ideas?
 
Thanks,
 
Steve