Lars Benedetto (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5bb1d56...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjEzNTZjYjBj...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17017?atlOrigin=eyJpIjoiMjEzNT...
) HHH-17017 (
https://hibernate.atlassian.net/browse/HHH-17017?atlOrigin=eyJpIjoiMjEzNT...
) Hibernate 6 cannot read VARCHAR column as INT (
https://hibernate.atlassian.net/browse/HHH-17017?atlOrigin=eyJpIjoiMjEzNT...
)
Issue Type: Bug Affects Versions: 6.2.7 Assignee: Unassigned Created: 31/Jul/2023 12:00 PM
Priority: Major Reporter: Lars Benedetto (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5bb1d56...
)
https://discourse.hibernate.org/t/hibernate-6-cannot-persist-enum-as-ordi...
As discussed in this thread, in Hibernate 6 if a column is VARCHAR, but actually contains
integers meant to be mapped with @Enumerated(value = EnumType.ORDINAL) then you’ll get an
exception caused by it using the char value of the int from the db as the ordinal index.
So a 0 in the db becomes a 48.
java.lang.ArrayIndexOutOfBoundsException: Index 48 out of bounds for length 2
at org.hibernate.type.descriptor.java.EnumJavaType.fromInteger(EnumJavaType.java:194)
at org.hibernate.type.descriptor.java.EnumJavaType.fromOrdinal(EnumJavaType.java:211)
at
org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter.toDomainValue(OrdinalEnumValueConverter.java:40)
at
org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter.toDomainValue(OrdinalEnumValueConverter.java:23)
In Hibernate 5, this worked without issue.
I have created a reproducer which I will link to in a few minutes.
(
https://hibernate.atlassian.net/browse/HHH-17017#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17017#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:da16c62 )