我的問題是我如何在JPA中執行UNION ALL子句? 是否可以使用@NamedQuery?這個查詢中使用2代表在每個SELECT語句並在結束它使用順序以時間BY如何在JPA中使用UNION ALL?
SELECT 0 as intorder, u.id, q.order_type
FROM test_union u, test_query q
WHERE u.id = q.id
AND u.type is NULL
AND q.field1 = 'DEFAULTS'
UNION ALL
SELECT 1 as intorder, u.id, q.order_type
FROM test_union u, test_query q
WHERE u.id = q.id
AND u.type is NOT NULL
AND q.field1 = 'TESTING'
UNION ALL
SELECT 2 as intorder, u.id, q.order_type
FROM test_union u, test_query q
WHERE u.id = q.id
AND u.type is NULL
AND q.field1 = 'DEFAULTS'
ORDER BY intorder, q.order_type;
你沒有。 JPQL中沒有這樣的東西。 –
那麼有沒有辦法在jpa中做到這一點? –
JPA允許您使用SQL查詢,然後丟棄數據庫獨立性。 –