Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of @XmlTransient with REST Webservices  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!