Skip to content
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

HHH-18783 cast(x as Character) on MySQL and Maria #9200

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

gavinking
Copy link
Member

@gavinking gavinking commented Nov 4, 2024

Based on #9194.

@cigaly WDYT?

[Please describe here what your change is about]


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-18783

          Method getSqlType for java.lang.Character without length should return "char(1)", not "char"
@cigaly
Copy link
Contributor

cigaly commented Nov 4, 2024

Hope that this will work. Only afraid that some things are very strange in MySQL.

Do you think that java.lang.Character should always be represented with something (char?) of length 1?

@gavinking
Copy link
Member Author

Do you think that java.lang.Character should always be represented with something (char?) of length 1?

I recently changed it to map to varchar(1) by default, because char columns are just too weird/broken.

@gavinking
Copy link
Member Author

I'm going to merge this because it fixes the bug. But notice that I've left a great big TODO, since the way MySqlAstTranslator. getSqlType() works isn't how we're supposed to handle customized mappings of cast target types, and we need to fix that because it's very fragile.

@gavinking gavinking closed this Nov 4, 2024
@gavinking gavinking reopened this Nov 4, 2024
@gavinking gavinking merged commit 18ccd6e into hibernate:main Nov 4, 2024
34 of 38 checks passed
@cigaly
Copy link
Contributor

cigaly commented Nov 5, 2024

Do you think that java.lang.Character should always be represented with something (char?) of length 1?

I recently changed it to map to varchar(1) by default, because char columns are just too weird/broken.

Unfortunately, in MySQL you can write cast(x as char(3)), but not cast(x as varchar(3))

In this particular case, if CastTarget.length was 1 for java.lang.Character, there will be no problem with cast(x as Character)

@gavinking
Copy link
Member Author

@cigaly Right, and that's a thing that is in principle supposed to be handled via the DdlType object which distinguishes the cast type from the column type.

Unfortunately, MySqlAstTranslator has deviated from the narrow path here, and is doing things its own way, and that's why this hack was necessary. I opened a JIRA issue to fix this.

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