2017-02-24 90 views
0

我試圖讓這個查詢在JPAMySQL查詢完美運行,但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

嗯,我看到了很多不同'order_header'和'OrderHeader' ...'order_detail' vs orderDetails ...在我看來他們不是相同的陳述.... –

回答

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 
+0

選擇h而不是選擇* – Katrin

+0

didn' t工作仍然沒有什麼 – user1863457

+0

我可以知道在查詢中導致問題的時間戳之間的區別嗎? – Katrin

0

當您創建實體之間的關係時,JPA查詢使用JOIN條件。

對於原始SQL查詢,您尚未提供ON條件,該條件將包含在JPA查詢中。

這是我看到的唯一區別。