Skip to content

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

Merged
merged 8 commits into from
Oct 2, 2024

Conversation

NathanQingyangXu
Copy link
Contributor

having year(order.dateTime) > 2003
and sum(quantity) > 0
having year > 2003
and yearlyTotalSold > 0
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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());

Copy link
Contributor Author

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.

Copy link
Member

@gavinking gavinking left a 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
Copy link
Member

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());

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Sep 13, 2024

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+
    ↳ Offending commits: [7bf67a7, 6804726, e854bb3, da6b136]

› This message was automatically generated.

@beikov
Copy link
Member

beikov commented Oct 2, 2024

Please squash all commits, then this can go in IMO.

@gavinking gavinking merged commit cef19d7 into hibernate:main Oct 2, 2024
17 of 20 checks passed
@gavinking
Copy link
Member

Thanks, @NathanQingyangXu! (I squashed it for you.)

@NathanQingyangXu
Copy link
Contributor Author

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.

@NathanQingyangXu NathanQingyangXu deleted the HHH-18605 branch October 2, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants