Skip to content

HHH-9812 @Formula with SQL cast function #10377

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 1 commit into from
Jun 27, 2025

Conversation

peter1123581321
Copy link
Contributor

@peter1123581321 peter1123581321 commented Jun 20, 2025

The formula CAST(foo AS signed) does not work on MySQL, because signed gets prefixed.
As suggested by @beikov on Jira, I implemented a bugfix in Template#renderWhereStringTemplate.
The fix is generic for all provided cast-types.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-9812

@gavinking
Copy link
Member

Hi @peter1123581321, thanks so much again for your contribution, and I'm really sorry to be the bad guy here again, but the argument to cast() in HQL is never a database column type. It doesn't make sense to cast to a database column type because in HQL expressions are assigned Java types.

From the documentation:

Its second argument is the target type given as an unqualified Java class name: String, `Long, Integer, Double, Float, Character, Byte, BigInteger, BigDecimal, LocalDate, LocalTime, LocalDateTime, etc.

The spec is even more restrictive about what is allowed here.

I don't know why that issue was never Rejected, but it should have been.

@gavinking
Copy link
Member

Oh wait. But the issue and this PR have nothing to do with HQL actually, despite the title.

They're actually about @Formula.

So maybe the pull request is fine.

@gavinking gavinking changed the title HHH-9812 HQL cast as signed with MySQL not working HHH-9812 @Formula with SQL cast function Jun 20, 2025
@gavinking
Copy link
Member

@peter1123581321 Would you please change the commit message to correctly reflect the nature of the change? Thanks.

@peter1123581321
Copy link
Contributor Author

Ah, sorry for the misunderstanding, I changed the commit message to the pr title.

I appreciate your role as the bad cop here. :D
It makes fun to dig in the hibernate source, but also takes some time of learning. ;-)

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.

LGTM

@gavinking gavinking merged commit cb1ead6 into hibernate:main Jun 27, 2025
22 of 25 checks passed
@gavinking
Copy link
Member

Thanks!!

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.

2 participants