aspose file tools*
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
Author

Use of @XmlTransient with REST Webservices

Harshad Khatawkar
Greenhorn

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

@XmlElement
public Museum getMuseum() {
return museum;
}

// getters and setters for other properties
}

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

@XmlElement
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.ws.rs.WebApplicationException: 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: com.museumdir.bo.Artifact@c51614 -> com.museumdir.bo.Museum@1d81ec9 -> com.museumdir.bo.Artifact@c51614]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:159)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown 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: http://aspose.com/file-tools
 
subject: Use of @XmlTransient with REST Webservices
 
Similar Threads
Returning a String from Server (REST) and getting Errors..
Jersey Hibernate Problem
rest webservice response problem when returning list
Web Service For Optical Character Recognition
Unable to Produce JSON - javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException