6

Does hibernate has support on select distinct on queries?

SELECT DISTINCT ON (location) location, time, report
FROM weather_reports
ORDER BY location, time DESC;

Is there a way to create hibernate criterias for that query?

froi
  • 5,720
  • 4
  • 33
  • 55

1 Answers1

4

Since there was all "suspecting" and "guessing" here, when I stumbled across this question, I'll answer it definitely:

No, Hibernate does not support a DISTINCT ON query.

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]

Tested under Hibernate 4.3.9-final

Please note that this doesn't apply to normal DISTINCT queries. See https://stackoverflow.com/questions/263850...

Community
  • 1
  • 1
Radall
  • 90
  • 1
  • 12