-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HHH-18605 fix some minor defects in Hibernate Query Language doc #8941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
having year(order.dateTime) > 2003 | ||
and sum(quantity) > 0 | ||
having year > 2003 | ||
and yearlyTotalSold > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not 100% sure, but seems usually having clause taps into aliases in the projection clause without duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Group by and order by clauses support using aliases, but other clauses don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran this code on postgres and it worked:
sessionFactory.inSession(s -> s.createSelectionQuery(
"select sum(book.quantity), year(book.publicationDate) from Book book " +
"group by year(book.publicationDate) " +
"having year(book.publicationDate) > 2003 " +
" and sum(book.quantity) > 0").getResultList());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted it back BEFORE I saw your comment. I googled further (e.g. https://stackoverflow.com/questions/72314037/how-can-i-use-an-alias-with-having-clause), so it seems the feature might not be supported by all DBs?
For that reason, I refrained from reverting back what I reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of good catches here, @NathanQingyangXu, but a couple of changes in comments.
having year(order.dateTime) > 2003 | ||
and sum(quantity) > 0 | ||
having year > 2003 | ||
and yearlyTotalSold > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran this code on postgres and it worked:
sessionFactory.inSession(s -> s.createSelectionQuery(
"select sum(book.quantity), year(book.publicationDate) from Book book " +
"group by year(book.publicationDate) " +
"having year(book.publicationDate) > 2003 " +
" and sum(book.quantity) > 0").getResultList());
Co-authored-by: Gavin King <[email protected]>
Co-authored-by: Gavin King <[email protected]>
Co-authored-by: Gavin King <[email protected]>
…b "commit suggestion"
Please squash all commits, then this can go in IMO. |
Thanks, @NathanQingyangXu! (I squashed it for you.) |
thanks! Glad I helped. As a community contributors, usually I could enjoy more on such doc polishing tickets so core team developers could focus on more important stuff. |
https://hibernate.atlassian.net/browse/HHH-18605