What is the correct JPA syntax when using union and order by?
At the moment I have something in the following manner:
SELECT st FROM Student st JOIN TREAT (st.type as HighShcool) hs
UNION
Select st FROM Student st JOIN TREAT (st.type as MiddleShcool) ms
ORDER BY st.id
This is failing and the exception that I am getting is the end of the query is wrong i.e ORDER BY section
. Without this, it is working.
Please help, I have no idea why it is happening.