我有4個實體,JAXB防止JAXB從一個共享實體序列化
purchaseRequest - 資金 - lineItemFunding purchaseRequest - LINEITEM - lineItemFunding - 資金
我使用JAXB和@XmlTransient
在lineItemFunding
上ManyToOne
關係。 >funding
- -
當從purchaseRequest
來,我不希望它掃描lineItemFunding
,但是從purchaseRequest
何時到來 - >lineItem
- >lineItemFunding
- >Funding
。我想要它對Funding
進行深層掃描。我碰到的問題是,如果我在lineItemFunding
的getFunding()
裏面使用@XmlTransient
,事情就完美了,但是如果我刪除它,會出現以下錯誤。
Caused by: com.sun.istack.SAXException2:
A cycle is detected in the object graph.
This will cause infinitely deep XML:
[email protected]
-> [email protected]
-> [email protected]
所以我的問題是,我如何防止它試圖從資金實體lineItemFunding做深度掃描。以下是我的來源。
PurchaseRequest
@OneToMany(mappedBy = "purchaseRequest", cascade = CascadeType.ALL, orphanRemoval = true)
private List<LineItem> lineItems;
@OneToMany(mappedBy = "purchaseRequest", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Funding> fundings;
資金
@OneToMany(mappedBy = "funding", cascade = CascadeType.ALL, orphanRemoval = true)
private List<LineItemFunding> lineItemFundings;
@XmlTransient
@ManyToOne
@JoinColumn(name = "purchase_request_id", nullable = false)
private PurchaseRequest purchaseRequest;
LINEITEM
@OneToMany(mappedBy = "lineItem", cascade=CascadeType.ALL, orphanRemoval=true, fetch=FetchType.EAGER)
private List<LineItemFunding> lineItemFundings;
@XmlTransient
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "purchase_request_id", nullable = false)
private PurchaseRequest purchaseRequest;
LineItemFunding
@XmlTransient
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "line_item_id", nullable = true)
private LineItem lineItem;
//需要刪除此xmlTransient以從lineItem方向深入掃描資金實體,但在資助方向上將其分開。因爲lineItemFunding只是對lineItem資金的一個連接,所以資金並不需要深入掃描linItemFunding。
@XmlTransient
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "funding_id", nullable = true)
private Funding funding;
感謝
@克里斯,謝謝克里斯,但在這種情況下,我不相信這會幫助我。然而,我會在下一次看看DTO。我認爲會有一些註釋可以應用於您的方法,以防止對象被進一步掃描。 – 2012-08-09 18:49:01