Suppose I have this enum:
Code:
public enum Status { OK, NOK, NOT_APPLICABLE }
And this property:
Code:
@Column(name = "status")
@Enumerated(EnumType.ORDINAL)
private Status status;
And this table (legacy, CANNOT be changed):
Code:
CREATE TABLE tb_xxx (
id bigint NOT NULL,
status character varying(1) NOT NULL,
)
It leads to this exception:
Code:
java.lang.IllegalArgumentException: No enum const class mypkg.Status.1
java.lang.Enum.valueOf(Enum.java:196)
org.hibernate.type.EnumType.nullSafeGet(EnumType.java:110)
Taking a look at
EnumType.java, it is clear that Hibernate imposes ordinal stored as number and name stored as varchar.
Is there any way to map enumeration ordinal as varchar?