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?
You can add the DISTINCT keyword to your query to tell Hibernate to return each Author entity only once. But as you can see in the following log messages, Hibernate also adds the DISTINCT keyword to the SQL query. This is often not intended and might result in an efficient database query.
Using distinct in the HQL Query We can notice that the distinct keyword was not only used by Hibernate but also included in the SQL query. We should avoid this because it's unnecessary and will cause performance issues.
Removing duplicate rows from a query result set in PostgreSQL can be done using the SELECT statement with the DISTINCT clause. It keeps one row for each group of duplicates. The DISTINCT clause can be used for a single column or for a list of columns.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With