I've written a JPQL statement that unions multiple select statements, each of which selects a different string constant. A simplified version of the query would look something like this:
SELECT DISTINCT 'A' AS widget_type
FROM WidgetA widgetA
WHERE widgetA.creationTimestamp > :cutoff
UNION SELECT DISTINCT 'B' AS widget_type
FROM WidgetB widgetB
WHERE widgetB.creationTimestamp > :cutoff
The query doesn't cause any errors but I'm not getting the result I expect. I see that the generated SQL doesn't have any unions - it only queries the table from the first select:
select distinct 'A' as col_0_0_
from widget_a widget0_
where widget0_.creation_timestamp>?
Is there an obvious reason why JPA would disregard everything after the first select statement? If it makes any difference, I am using Hibernate 4.1.9 as the JPA implementation, with a MySQL database.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…