我正在使用Spring + Hibernate + cxf作为Android服务。但是当我返回结果时:
return Response.ok(userInfo).header("EntityClass", "testUsetInfo").build();
它显示了一个例外:
org.apache.cxf.jaxrs.provider.AbstractJAXBProvider handleExceptionStart<br/>
警告: javax.xml.bind.MarshalException<br/>
- with linked exception:<br/>
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML<br/>
TransPackage[ ID=1111111111 ...] -> TransPackageContent[Pkg.Persist_ID=1111111111 ...] -> TransPackage[ ID=1111111111 ...]]
是的,我这样使用它:
@Entity
@org.hibernate.annotations.Proxy(lazy=false)<br/>
@Table(name="TransPackage")<br/>
@XmlRootElement(name="TransPackage")<br/>
public class TransPackage implements Serializable {
@OneToMany(mappedBy="pkg", targetEntity=TransPackageContent.class)
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})
@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
private java.util.Set<TransPackageContent> content = new java.util.HashSet<TransPackageContent>();
//getters() and setters();
}
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="TransPackageContent")
@XmlRootElement(name="TransPackageContent")
public class TransPackageContent implements Serializable { @ManyToOne(targetEntity=TransPackage.class, fetch=FetchType.LAZY) @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK}) @JoinColumns({ @JoinColumn(name="PackageID", referencedColumnName="ID", nullable=false) }) private TransPackage pkg; //getters() and setters(); }
但是如果我在课前添加@XmlTransient,它会显示如下的异常:
Caused by: com.sun.istack.SAXException2: class com.htzy.extrace.model.TransPackage以及其任何超类对此上下文都是未知的。
javax.xml.bind.JAXBException: class com.htzy.extrace.model.TransPackage以及其任何超类对此上下文都是未知的。
我该怎么办?
非常感谢,我很抱歉我的英语很差!
答案 0 :(得分:0)
是的!! @ XmlTransient有效,它是在getters()
之前添加的//like this
@XmlTransient
public TransPackage getPkg(){
return pkg;
}