我有4个实体,
purchaseRequest - 资金 - lineItemFunding purchaseRequest - lineItem - lineItemFunding - 资金
我正在使用 JAXB 并建立@XmlTransient
关系。lineItemFunding
ManyToOne
当来自purchaseRequest
-> funding
- 我不希望它扫描lineItemFunding
时,但来自purchaseRequest
-> lineItem
-> lineItemFunding
-> Funding
。我希望它对Funding
. 我遇到的问题是,如果我@XmlTransient
在getFunding()
内部使用lineItemFunding
,一切正常,但如果我删除它,我会收到以下错误。
Caused by: com.sun.istack.SAXException2:
A cycle is detected in the object graph.
This will cause infinitely deep XML:
org.company.com.entities.Funding@2a2
-> org.company.com.entities.LineItemFunding@82
-> org.company.com.entities.Funding@2a2
所以我的问题是,如何防止它尝试从资助实体对 lineItemFunding 进行深度扫描。以下是我的来源。
采购申请
@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;
行项目
@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 方向深度扫描资金实体,但在资金方向中断它。资金不需要深入扫描 linItemFunding,因为 lineItemFunding 只是资金与 lineItem 的连接。
@XmlTransient
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "funding_id", nullable = true)
private Funding funding;
谢谢