1
votes

I'm using Spring+Hibernate+cxf for a Android Service.but when I return the result:
return Response.ok(userInfo).header("EntityClass", "testUsetInfo").build();
it show a exception:

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 ...]]

yes, I use it like this:

@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(); }

but if I add @XmlTransient before the class, it show the exception like this:

    Caused by: com.sun.istack.SAXException2: class com.htzy.extrace.model.TransPackage以及其任何超类对此上下文都是未知的。
javax.xml.bind.JAXBException: class com.htzy.extrace.model.TransPackage以及其任何超类对此上下文都是未知的。

what can I do?

Thanks a lot, and I am sorry for my poor English!

1

1 Answers

0
votes

yes!!@XmlTransient works,it was add before the getters()

//like this
@XmlTransient
public TransPackage getPkg(){
    return pkg;
}