aspose file tools
The moose likes Web Services and the fly likes jax-ws : return list of JPA entities Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "jax-ws : return list of JPA entities" Watch "jax-ws : return list of JPA entities" New topic
Author

jax-ws : return list of JPA entities

Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 199
Hi,

I am developing a simple jax-ws service for an iphone application. I am using EJB 3.0 entities and hibernate as JPA implementation.

I'll have a operation getUsers, that should return the list of users with all the attributes of users fetched from DB.

If I return something like this :




The problem is that I am unable to make my web service deployed If I use generics.

And if I remove generic code and rather use normal "List", the web service is deployed but if I call this service I get an exception.

My question is, if I am somehow able to resolve the problem, will the jax-ws runtime be able to send the SOAP message something like this :



I suspect this is not possible, I guess I will have to create xml manually ? But then what's use of using jax-ws ?

Can someone help me out on this? I need to send the data from the JPA entities in xml form.

Thanks


Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2193
Hello!
First of all, do not use the List type as a return type form a web service method. Use arrays instead.
JAXB, who is responsible for marshalling and unmarshalling XML data does not know about Lists, since this is not a simple Java type.
Arrays, however, is no problem for JAXB.

Second, when querying for entities from a database or such, be sure not to use lazy loading and also detach the entities from the entity context before returning them.
This because if you, for instance, use lazy loading and return entities which data is not completely loaded, then there may be problems if the entity context is closed when the serialization of the entities to XML is done.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: jax-ws : return list of JPA entities
 
Similar Threads
problem converting xml into bean using betwixt
design decision: variation of session fassade
Call to webservice returning with a response status 500 throws UniformInterfaceException
Need help for Many to Many association
Sample Questions for 288 - Need answers