【发布时间】:2012-07-16 11:11:32
【问题描述】:
我有一个名为 Status 的枚举类,如下所示
public enum Status {
PENDING(0), SUCCESS(1), FAILED(-1);
private int st;
private Status(int st){
this.st = st;
}
}
从其他类我尝试映射这个状态枚举
public void setStatus(Status status) {
this.status = status;
}
@Enumerated(EnumType.ORDINAL)
public Status getStatus() {
return status;
}
当我运行这段代码时,我得到了
java.lang.IllegalArgumentException:枚举类数据的未知序数值。状态:-1 在 org.hibernate.type.EnumType.nullSafeGet(EnumType.java:93) 在 org.hibernate.type.CustomType.nullSafeGet(CustomType.java:124) 在 org.hibernate.type.AbstractType.hydrate(AbstractType.java:106) 在
但我在枚举定义中已经有了 -1。
【问题讨论】:
标签: java hibernate exception enumeration