We have an entity with an enum field that we'd like to persist the value of as a string. In Hibernate 4.3.11 this worked as expected. After uplifting to Hibernate 5.0.7 when we try and read from the enum field we get this error
Caused by: java.sql.SQLException: Invalid value for getInt() - 'DESTINATION'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2826)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2851)
at org.hibernate.type.EnumType$OrdinalEnumValueMapper.getValue(EnumType.java:337)
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:231)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:110)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2727)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1728)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1654)
at org.hibernate.loader.Loader.getRow(Loader.java:1543)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727)
at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
at org.hibernate.loader.Loader.doQuery(Loader.java:930)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2611)
... 57 more
Writing to the enum field writes the ordinal of the enum instead of the value (ie 0 instead of DESTINATION) We can read back new values written with 5.0.7 but we can not read back old values written with 4.3.11. Our entity is defined like this (extra fields removed)
public class TransportConfig implements Serializable {
private String identifier;
public enum Type {
DESTINATION,
REPLICATION
}
}
Which is mapped with this mapping file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-
"http:>
<hibernate-mapping>
<class name=“my.class.TransportConfig" table="transportconfig">
<id name="identifier" type="java.lang.String" access="field">
<column name="transport_id" sql-type="varchar(191)"/>
<generator class="assigned" />
</id>
<property name="type" access="field" not-null="true">
<column name="type" sql-type="varchar(50)"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">my.class.TransportConfig$Type</param>
</type>
</property>
</class>
</hibernate-mapping>
We made no code changes when uplifting to 5.0.7...just changed the pom dependencies. Is there something we missed that needs to change for the enums to retain their historical behavior? |