Skip to content

HHH-17017 Hibernate 6 cannot read VARCHAR column as INT #8890

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dreab8
Copy link
Member

@dreab8 dreab8 commented Sep 5, 2024

The test shows that using @JdbcTypeCode(SqlTypes.VARCHAR) fixes the issue;


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

Copy link
Member

@beikov beikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, IMO the suggestion to use @JdbcTypeCode(VARCHAR) is the way to go. I'm surprised this worked before in ORM 5.

@gavinking
Copy link
Member

I guess the source of user confusion here is that usually IntegerJavaType will automatically do conversion from String to Integer. EnumJavaType doesn't do such a conversion, it assumes Strings are names, I think because EnumJavaType doesn't actually properly know whether it is an ORDINAL or STRING enum mapping.

I agree with you guys that this is a pretty minor discomfort because the workaround is so easy.

@dreab8
Copy link
Member Author

dreab8 commented Sep 12, 2024

I was wrong, as commented on the Jira, when using @JdbcTypeCode(SqlTypes.VARCHAR) the string value is persisted.
In the Jira I proposed other two solutions.
In previous version it worked because it seems MySQL has no issues using an IntegerJdbcType even when the db column is a varchar, while it has issue when using a TinyIntJdbcType

@gavinking
Copy link
Member

gavinking commented Sep 12, 2024

Ah OK. I think this is slightly less than trivial to fix because as I said:

EnumJavaType doesn't actually properly know whether it is an ORDINAL or STRING enum mapping.

But I have not dug deep and so maybe that's wrong.

@dreab8
Copy link
Member Author

dreab8 commented Sep 12, 2024

yes, probably we would need an OrdinalEnumType and a StringEnumType, anyway I think that persisting an oridnal enum into a varchar column is really an edge case

@gavinking
Copy link
Member

gavinking commented Sep 12, 2024

I think that persisting an oridnal enum into a varchar column is really an edge case

I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants