我有两个实体
public class Invoice {
@Id
@GeneratedValue
@Column(name = "id_invoice")
private long id;
@OneToMany(mappedBy = "invoice", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<InvoiceLine> invoiceLineList;
}
和
public class InvoiceLine {
@Id
@GeneratedValue
@Column(name = "id_invoice_line")
private long id;
@ManyToOne(fetch = FetchType.LAZY)
private Invoice invoice;
}
我有一个HQL查询用户,用于检索带有相关发票行的发票
SELECT i FROM Invoice as i left outer join fetch i.invoiceLineList as invoiceLines WHERE i.id=(:id)
正确检索发票,但问题是在发票行列表中,对象&#34;发票&#34;已设定。这是一个很大的问题,因为我有一个序列化此发票的方法,它返回StackOverflow例外(发票 - &gt; invoiceLine - &gt;发票 - &gt; invoiceLine - &gt; ...)
如何避免这个父实体集?