我想将我的SQL查询转换为HQL或JPQL(我希望从对象映射中受益)。
我的SQL请求如下:
SELECT *
FROM (SELECT bde, MAX(creation_date)
FROM push_campaign GROUP BY bde) temp,
push_campaign pc where pc.bde = temp.bde and pc.creation_date = temp.creation_date;
我尝试使用以下JPQL进行转换,但未成功:
select pc
from (select bde, max(creationDate)
from PushCampaign group by bde) temp,
PushCampaign pc
where pc.bde = temp.bde and pc.creationDate = temp.creationDate
但我被提高了:
IllegalArgumentException occured :
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 16 [select pc from (select id, max(creationDate) from models.PushCampaign group by bde) temp, models.PushCampaign pc where pc.id = temp.id]
我了解到嵌套查询只能在select或where子句中使用。
您是否有解决方案来保留对象映射的请求和利益?
INNER JOIN
而不是在WHERE
子句中进行连接吗? - Adriano Carneiro