I am having a problem I do not fully understand. I have a legacy database schema that stores ordinal values for enumerations as char(1). I have the following mapping:
Code:
/** The current status of this case. */
@Column(name="STATUS", columnDefinition="char(1)")
private Status status;
This works OK for create, but on read I get the following exception:
Code:
Caused by: java.lang.IllegalArgumentException: No enum const class foo.bar.bam.Case$Status.2
at java.lang.Enum.valueOf(Enum.java:192)
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:101)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
Here's what I don't understand, it seems to me if Hibernate can store the value correctly (as an ordinal), it ought to be able to read it correctly. It looks like there is a mismatch in the logic for EnumType.nullSafeGet and EnumType.nullSafeSet
I am looking into authoring a UserType for this scenario, but I wanted to confirm that this is what is required and that I haven't missed something.