It's not a secret anymore!
The moose likes Web Services and the fly likes jax-ws : return list of JPA entities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "jax-ws : return list of JPA entities" Watch "jax-ws : return list of JPA entities" New topic

jax-ws : return list of JPA entities

Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 201

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.


Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
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:
I agree. Here's the link:
subject: jax-ws : return list of JPA entities
It's not a secret anymore!