hibernate-orm icon indicating copy to clipboard operation
hibernate-orm copied to clipboard

HHH-17017 Hibernate 6 cannot read VARCHAR column as INT

Open dreab8 opened this issue 1 year ago • 5 comments

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 avatar Sep 05 '24 13:09 dreab8

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.

gavinking avatar Sep 12 '24 10:09 gavinking

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

dreab8 avatar Sep 12 '24 10:09 dreab8

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.

gavinking avatar Sep 12 '24 10:09 gavinking

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

dreab8 avatar Sep 12 '24 10:09 dreab8

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

I agree.

gavinking avatar Sep 12 '24 10:09 gavinking