我有一个使用JPA实体类的JAX-RS Web服务。我有这样的资源类:
@Path("/entity")
public class MyEntityResource
{
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/{entity}")
public MyEntity getMyEntity(@PathParam("entity") String entity)
{
log.debug("Entering getMyEntity with param: " + entity);
MyEntity entityObject = genericService.find(MyEntity.class, entity);
if (entityObject == null)
{
log.debug("Entity not found.");
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
log.debug("Exiting getMyEntity");
return entityObject;
}
}
当我运行该服务并对该实体进行get调用时,我收到此错误:
SEVERE: The response of the WebApplicationException cannot be utilized as the response is already committed. Re-throwing to the HTTP container
javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
- with linked exception:
[Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred marshalling the object
Internal Exception: java.lang.NullPointerException]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:151)
...
<snip>
...
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred marshalling the object
Internal Exception: java.lang.NullPointerException]
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:271)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:171)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:149)
... 32 more
Caused by: Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred marshalling the object
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.XMLMarshalException.marshalException(XMLMarshalException.java:76)
at org.eclipse.persistence.oxm.XMLMarshaller.marshal(XMLMarshaller.java:502)
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:269)
... 34 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.ConversionException.couldNotBeConverted(ConversionException.java:69)
...
<snip>
...
at org.eclipse.persistence.oxm.XMLMarshaller.marshal(XMLMarshaller.java:916)
at org.eclipse.persistence.oxm.XMLMarshaller.marshal(XMLMarshaller.java:468)
... 35 more
任何堆栈跟踪都没有引用我的任何类。此外,在异常之前记录"Exiting getMyEntity"
语句。
我不知道是什么抛出NPE或如何调试它。
在此错误之前,我从我的JPA(EclipseLink)实体类中获取了[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML:
,并在父getter方法上将注释MOXy @XmlInverseReference添加到了我的子类。
关于什么可能引发此异常的任何想法?
答案 0 :(得分:4)
答案 1 :(得分:1)