-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Hibernate and Axis web service
PostPosted: Wed Jan 12, 2005 5:08 pm 
Regular
Regular

Joined: Sat May 15, 2004 4:27 am
Posts: 79
Is there any body who is working both hibernat and axis. Who
how can i map hibernate bean (POJO) for axis ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 6:08 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
I've done it and it works great.

Short answer: Hibernate and Axis both deal with POJO's so you'll be fine.

Long(er) answer: You'll want to watch out for Lazy Initialization Exceptions because when Axis serializes the Hibernate object, chances are good that it will try to serialize the WHOLE object. If your Hibernate Session is not open, you may see Lazy Initialization Exceptions. The solution is to keep your session open and limit the methods accessible to the object in Axis. Also, you'll want to watch out for too much data being serialized. Axis can go crazy and serialize your whole object graph. You can solve this using Lazy collections and proxied objects and if things get really interesting you might need to use a custom serializer for axis to detect Hibernate proxy objects and only serialize the ID and Version.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 7:29 pm 
Regular
Regular

Joined: Sat May 15, 2004 4:27 am
Posts: 79
I am using lazy collections. When i try to use my collections, which
are set, axis try to map them I don't know how to map the Set of
my beans and limit the axis methods exploration.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:13 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Do you have your objects marked as proxied? Not sure if that will do anything, but make sure that you use the proxy="xxx" in the mapping of the classes. That will ensure a proxied approach. If that still doesn't prevent Axis from digging too deep you may have to write a custom axis serializer that is smart about handling Hibernate proxies and only accesses the ID and Version.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 11:22 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
what is meant by a proxy??? i could not find any details about this term anywhere...can someone explain??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 2:48 pm 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Hi cardsharp,
In your persistent classes you might be having member variables of type Set, List or Bag. These types cannot be passed through webservice...

how are you managing this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 6:15 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Hibernate is capable of generating a "Proxy" for your object on the fly. What it does is dynamically sublcass your object and enhances it. Proxies only have ID and Version data loaded. When you access one of the other pieces of information on the object, Hibernate loads the rest of the data into the object.

Proxies are used in lazy collections and in one-to-one and many-to-one relationships. Proxies are serializable, though many serialization engines get too agressive and trigger the materialization of the object. Often if you want to serialize the relationship, you have to write a custom serializer to make sure only the ID and Version are taken along for the ride.

Also, be aware that if the Proxy is serialized in it's de-materialized state and you don't have an active Hibernate Session (on the remote machine, for example), you will get LazyInstantiation exceptions if you try to access any property other than the ID or Version.

In Axis, one strategy is to create a custom serializer that can deal properly with Proxies and lazy collections either by initializing the proxy or by only converting the ID and Version.

As for serializing collections, Axis 1.2 has support for automatic conversion of Collections into SOAP arrays, but I still recommend a custom serializer to keep Axis from fully initializing proxies and lazy collections.

Not sure what happens with Interop with things like .NET when you use Axis collection serialization... time for some experimentation!


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Jan 25, 2013 9:48 am 
Newbie

Joined: Fri Jan 25, 2013 9:33 am
Posts: 1
cardsharp wrote:
I've done it and it works great.

Short answer: Hibernate and Axis both deal with POJO's so you'll be fine.

Long(er) answer: You'll want to watch out for Lazy Initialization Exceptions because when Axis serializes the Hibernate object, chances are good that it will try to serialize the WHOLE object. If your Hibernate Session is not open, you may see Lazy Initialization Exceptions. The solution is to keep your session open and limit the methods accessible to the object in Axis. Also, you'll want to watch out for too much data being serialized. Axis can go crazy and serialize your whole object graph. You can solve this using Lazy collections and proxied objects and if things get really interesting you might need to use a custom serializer for axis to detect Hibernate proxy objects and only serialize the ID and Version.


You just saved my day with this reply, it was really helpful.

I couldn't keep my session opened and the @Proxy annotation didn't work fine (I think I'm too dumb to get this working), so I looked for other solutions.
I specified the @XmlAccessorType annotation to my entity and to the fields I didn't want to bring I put @XMLTransient annotation so axis don't try to serialize them.
The post bellow helped me a lot:
http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html

I hope this helps others with the same problem.

I am really sorry for my awful spelling, just wanted to help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.