4
我有一个枚举如下。在hibernate hbm中映射枚举?
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;
}
}
我需要保存整数值而不是ONE和TWO。我怎样才能做到这一点?我有我的hbm下面的配置:
<property name="action">
<column name="ACTION" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.ExampleEnum</param>
</type>
</property>
我需要有任何其他配置来保存整数?请帮帮我!
谢谢!
'所有的持久化类必须有一个默认的构造方法(可以是非公共的)这样的话Hibernate就可以使用Constructor.newInstance实例化它们()。建议您有一个默认的构造函数,至少包可见性,以便在Hibernate中生成运行时代理代理。“ – 2013-04-05 10:47:19
https://forum.hibernate.org/viewtopic.php?p=2377095 – Thihara 2013-04-05 10:53:14
可能的重复。看到这个问题:http://stackoverflow.com/questions/9839553/hibernate-map-enum-to-varchar?rq=1 – dcernahoschi 2013-04-05 10:54:19