任何人都可以帮我将此查询转换为HQL
SELECT
supplierOrderDetails.productID,
supplierOrderDetails.orderQty,
supplierOrderReceiveDetail.qtyArrived
FROM
supplierOrder
INNER JOIN
supplierOrderDetails
ON
(supplierOrderDetails.supplierOrderID = supplierOrder.ID)
INNER JOIN
supplierOrderReceive
ON
(supplierOrderReceive.supplierOrderID = supplierOrder.ID)
INNER JOIN
supplierOrderReceiveDetail
ON
(supplierOrderReceiveDetail.supplierOrderReceiveID = supplierOrderReceive.ID)
AND
(supplierOrderReceiveDetail.ProductID =supplierOrderDetails.ProductID)
WHERE supplierOrder.ID = 1
这是表关系
答案 0 :(得分:4)
我已经为想要了解如何在HQL中加入多个表的人添加了查询
SELECT supplierOrderDetails.productID as product, supplierOrderDetails.orderQty as orderedQty,sum(supplierOrderReceiveDetail.qtyArrived) as qtyArrived
FROM SupplierOrder as so, SupplierOrderDetails as supplierOrderDetails, SupplierOrderReceiveDetail as supplierOrderReceiveDetail, SupplierOrderReceive as supplierOrderReceive
INNER JOIN supplierOrderDetails.supplierOrderID
INNER JOIN supplierOrderReceive.supplierOrder
INNER JOIN supplierOrderReceiveDetail.supplierOrderReceive
GROUP BY supplierOrderDetails.productID, supplierOrderDetails.orderQty
答案 1 :(得分:0)
这个链接很适合开始学习如何通过HQL加入实体。
编辑:
对于hibernate加入实体,您必须在实体之间定义关联/映射
Hibernate使用Hibernate映射文件中定义的关系名称。
答案 2 :(得分:0)
HQL使用您映射的Entities
并返回Entities
。因此,根据您的hibernate(JPA)映射,您想要的HQL可以简单如下:
来自SupplierOrder的,其中id = 1