我有 3 个表,因为 LetterOfCredit 有许多 ProformatInvoice,其中有许多 PurchasingOrder。
我想在我的实体 LetterOfCredit 中获取通过 ProformatInvoice 链接的所有采购订单的列表。
在 SQL 中它看起来像:
SELECT *
FROM purchase_order
JOIN proformat_invoice pi ON pi.id = pi_id
JOIN letter_of_credit lc ON lc.id = pi.lc_id
WHERE lc_id = 3;
但是在 LetterOfCredit.java 中,我尝试使用 proformat_invoice 作为可连接项,但我得到一个空列表......
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(
name="proformat_invoice",
joinColumns = @JoinColumn(name="lc_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name="id", referencedColumnName = "pi_id")
)
private List<PurchaseOrder> purchaseOrders;
你能告诉我我做错了什么吗?
最佳答案
We can fetch the grand children efficiently by using hibernate annotation ---- @OneToMany( mappedBy = "category", fetch = FetchType.LAZY ).
So in this case this will not give an exception if its unable to fetch the sub children till session is open.
We can manually pull the sub children by using the getters in our code without getting any exception , as we have already told the compiler that it will be lazy loading because there are child elements and there sub child elements.
关于java - 如何使用 Hibernate 注释获取孙子表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33498613/