File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Use of @XmlTransient with REST Webservices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Use of @XmlTransient with REST Webservices" Watch "Use of @XmlTransient with REST Webservices" New topic

Use of @XmlTransient with REST Webservices

Harshad Khatawkar

Joined: Aug 19, 2011
Posts: 1
I have the following 2 business objects:
public class Artifact {
private Museum museum;
// other properties

public Museum getMuseum() {
return museum;

// getters and setters for other properties

public class Museum {
private Set<Artifact> artifactList;
// other properties

public Set<Artifact> getArtifactList() {
return artifactList;

// getters and setters for other properties

When I try to get a Museum by specifying the museum_id or when I try to get a Artifact by specifying the artifact_id, I am getting the following exception:
Aug 17, 2013 8:21:16 PM com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error) javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: -> ->]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(
at com.sun.jersey.spi.container.ContainerResponse.write(
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(
at com.sun.jersey.spi.container.servlet.WebComponent.service(
at com.sun.jersey.spi.container.servlet.ServletContainer.service(
at com.sun.jersey.spi.container.servlet.ServletContainer.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
at Source)

I was able to resolve this issue by specifying the @XmlTransient for the above mentioned getter methods in the given Museum and Artifact class. But after specifying this, I could not get the completely populated business objects i.e if I queried an artifact for a given id, the museum field in the returned object was null. Similarly when I tried to query a museum for a given id, the list of artifacts returned were null.

I am using Hibernate for fetching these objects from database. How do I resolve this ? I want to get the completely populated business objects.

I agree. Here's the link:
subject: Use of @XmlTransient with REST Webservices
jQuery in Action, 3rd edition