我需要形成一个 HQL 查询,该查询返回多个看起来像这样的实体对象:
/*
* Want to return both H and C in the same query...
*/
SELECT H, C
/*
* ... such that H is the most recent entry...
*
* (Note that 'ON' keyword does not work with HQL)
*/
FROM HealthHistory H INNER JOIN (
SELECT id, MAX(insertion_time) insertion_time
FROM HealthHistory
GROUP BY id
) IH ON H.id = IH.id AND IH.insertion_time = H.insertion_time
/*
* ... while getting these other entities involved...
*/
LEFT JOIN NodeA A
LEFT JOIN NodeC C
LEFT JOIN NodeL L
/*
* ... so we can add some more expressions here...
*/
WHERE A.someId = C.descendant.id -- A -> C
AND A.something = someConstant
AND C.someId = L.id -- C -> L
AND C.something = someConstant
AND L.something = someConstant
AND H.someId = C.id -- H -> C
AND H.something = someConstant
我不断收到org.hibernate.hql.ast.QuerySyntaxException: unexpected token: {(, A, ON, or INNER}
即使在查看了许多类似的问题之后,我也已经挣扎了很长一段时间。对此的任何帮助表示赞赏...