我试图让这个查询在JPA中起作用
它在mysql中完美运行:
select * from order_header join order_detail where (order_header.buying_partner_id = 1 or order_header.buying_partner_id = 3) AND ((order_detail.warehouse_id = 6) or (order_header.warehouse_id = 6 and order_detail.warehouse_id is null ) ) and (order_detail.tracking_number is null or order_detail.tracking_number = '') and order_detail.canceled != 1 and (order_header.order_num is NOT NULL and order_header.order_num != '') and order_header.timestamp > '2017-01-24 08:33:00.096' group by order_header.order_num order by order_header.comment DESC;
返回结果。
JPA查询:
Select h FROM OrderHeader h JOIN h.orderDetails d WHERE ( h.buyingPartner.id = 1 or h.buyingPartner.id = 3 ) AND ( (d.warehouse.id =6) OR ( h.warehouse.id =6 AND d.warehouse.id IS null ) ) AND (d.trackingNumber IS null or d.trackingNumber = '') AND d.canceled != 1 AND (h.orderNum IS NOT null AND h.orderNum != '') and h.timestamp > '2017-01-24 09:32:39.865' GROUP BY h.orderNum ORDER BY h.comment DESC
它什么都不返回。没有错误。什么都不回报。
这些是完全相同的陈述。
我的JPA声明一定有问题。
答案 0 :(得分:0)
Select h FROM OrderHeader h JOIN h.orderDetails d WHERE ( h.buyingPartner.id = 1 or h.buyingPartner.id = 3 ) AND ( (d.warehouse.id =6) OR ( h.warehouse.id =6 AND d.warehouse.id IS null ) ) AND (d.trackingNumber IS null or d.trackingNumber = '') AND d.canceled != 1 AND (h.orderNum IS NOT null AND h.orderNum != '') and h.timestamp > '2017-01-24 09:32:39.865' GROUP BY h.orderNum ORDER BY h.comment DESC
答案 1 :(得分:0)
JPA Query在您创建实体之间的关系时使用JOIN
条件。
对于原始SQL查询,您没有提供ON
条件,该条件将包含在JPA查询中的默认值。
这是我在其中看到的唯一区别。