0
我想寫一個相當複雜的JPQL語句,它根據另一個表中的值對結果進行排序。我知道MySQL會是什麼樣子,但我需要幫助將它變成JPQL。這是等效的SQL:複雜的JPQL ORDER語句
SELECT o.* FROM Observation o
LEFT JOIN Obs_Event p
ON p.Event_ID = o.Event_ID
LEFT JOIN Event_Set ppp
ON ppp.Event_ID = o.Event_ID AND ppp.Event_Set_ID = o.Event_Set_ID
WHERE o.Individual_ID = <some id>
AND o.Observation_Date = <a date value>
ORDER BY ppp.Seq_Num ASC
任何關於如何做到這一點的幫助將不勝感激。具體來說,我似乎有這個部分的麻煩:
ON ppp.Event_ID = o.Event_ID AND ppp.Event_Set_ID = o.Event_Set_ID
所以,到目前爲止,我已經試過這樣:
Query q= em.createQuery("select o " +
" from Observation as o " +
" join o.eventID p" +
" join p.eventSetCollection ppp " +
" where o.individualID = :indiv " +
" AND o.observationDate = :d " +
" AND o.eventID = ppp.event " +
"";
如果我嘗試添加像
WHERE ...
AND o.eventSetID = ppp.eventSet
...它根本不起作用。如果我查看生成的SQL,它看起來像ppp.eventSet被忽略。
對此提出建議?
您的實體如何映射? – axtavt 2011-02-09 10:22:56