我正在尝试实现一个在表Document和DocumentField之间具有关系数据库逻辑的解决方案。此解决方案将用作Web服务,并将由客户端使用。 我从我的Web服务客户端收到以下异常:
Exception: javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.bla.bla.ws.Document@115cfb9 -> com.bla.bla.ws.DocField@94e6ee -> com.bla.bla.ws.Document@115cfb9]
为了解决这个问题,我添加了@XmlTransient注释:
文件:
@Entity(name = "Document")
@Table(name = "DOCUMENT", schema = "DOCUMENT")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Document extends BasicObject implements Serializable {
private static final long serialVersionUID = -5274375009324738532L;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="doc")
@XmlTransient
private List<DocField> extraInfo;
DocField:
public class DocField extends BasicObject implements Serializable {
private static final long serialVersionUID = -7403660716697161123L;
@ManyToOne
@JoinColumn(name="DOC_ID")
@XmlTransient
private Document doc;
但是现在我无法通过此代码片段从客户端访问我的docField:
Document testDoc = new Document ();
DocField testDocField = new DocField();
testDoc.getDocField.add(testDocField);
我想我误解了这种解决方案中的一些观点。任何人都可以提供一些解释吗?还是任何外部资源?