Skip to content

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

@dreab8 dreab8 force-pushed the HHH-17017 branch 2 times, most recently from 01917bd to 15d4db3 Compare September 6, 2024 10:06
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.

@dreab8 dreab8 merged commit c46738f into hibernate:main Oct 2, 2025
23 of 25 checks passed
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