Hibernate在查询中是否支持SELECT DISTINCT?
SELECT DISTINCT ON (location) location, time, report
FROM weather_reports
ORDER BY location, time DESC;
有没有一种方法可以为该查询创建Hibernate标准?
Hibernate在查询中是否支持SELECT DISTINCT?
SELECT DISTINCT ON (location) location, time, report
FROM weather_reports
ORDER BY location, time DESC;
由于这里有很多“怀疑”和“猜测”,所以当我遇到这个问题时,我会明确回答:
不,Hibernate不支持DISTINCT ON查询。
org.hibernate.hql.internal.ast.QuerySyntaxException:
unexpected token: ON near line 1, column 17
[SELECT DISTINCT ON (location) location, time, report FROM weather_reports ORDER BY location, time DESC]
在 Hibernate 4.3.9-final 下测试通过。
请注意,这不适用于普通的 DISTINCT 查询。 请参阅 https://dev59.com/3nVC5IYBdhLWcg3wihmv...