[https://discourse.hibernate.org/t/hibernate-6-cannot-persist-enum-as-ordinal-in-varchar-column/7775/17|https://discourse.hibernate.org/t/hibernate-6-cannot-persist-enum-as-ordinal-in-varchar-column/7775/17|smart-link]
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.
{noformat}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) {noformat}
In Hibernate 5, this worked without issue.
I have created a reproducer which I will link to in a few minutes [https://github . com/lbenedetto/HHH-17017-Issue-Reproducer|https://github.com/lbenedetto/HHH-17017-Issue-Reproducer|smart-link] |
|