user1479203 user1479203 - 8 months ago 52
Java Question

How to map custom enumurated integer ordinals with hibernate

I have an enum class named Status as follows

public enum Status {

private int st;

private Status(int st){ = st;

and from other class I try to map this status enum

public void setStatus(Status status) {
this.status = status;

public Status getStatus() {
return status;

when I run this code, I get

java.lang.IllegalArgumentException: Unknown ordinal value for enum class data.Status: -1
at org.hibernate.type.EnumType.nullSafeGet(
at org.hibernate.type.CustomType.nullSafeGet(
at org.hibernate.type.AbstractType.hydrate(

but I already have -1 in enum definition.


You could define your own UserType which defines how Hibernate should map those enums.

Note that the ordinal defines the index of the enum value and thus FAILED would have the ordinal 2. To map the enum using its properties your need a UserType implementation.

Some links: