【发布时间】:2013-03-27 17:50:59
【问题描述】:
我有一个如下的枚举。
public enum ExampleEnum {
ONE(1), TWO(2);
private int action;
private ExampleEnum (int action){
this.action = action;
}
/**
* @return the action
*/
public int getAction() {
return action;
}
/**
* @param action the action to set
*/
public void setAction(int action) {
this.action = action;
}
}
我需要保存整数值,而不是一和二。我怎样才能做到这一点?我的 hbm 中有以下配置:
<property name="action">
<column name="ACTION" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.ExampleEnum</param>
</type>
</property>
我需要任何其他配置来保存整数吗?请帮帮我!
谢谢!
【问题讨论】:
-
All persistent classes must have a default constructor (which can be non-public) so that Hibernate can instantiate them using Constructor.newInstance(). It is recommended that you have a default constructor with at least package visibility for runtime proxy generation in Hibernate. -
可能重复。看到这个问题:stackoverflow.com/questions/9839553/…