Java 在hibernate hbm中映射枚举?
我有一个枚举如下Java 在hibernate hbm中映射枚举?,java,hibernate,Java,Hibernate,我有一个枚举如下 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;
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;
}
}
我需要保存整数值,而不是1和2。我该怎么做?我的hbm中有以下配置:
<property name="action">
<column name="ACTION" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.ExampleEnum</param>
</type>
</property>
com.ExampleEnum
我是否需要任何其他配置来保存整数?请帮帮我
谢谢 `
<class name="package.class" table="database table name">
<id name="get/set parameter....your first attribute" type="int" column="data base columnname">
<generator class="increment"/><!--using auto increment-->
</id>
<property name="get/set parameter your second attribute">
<column name="data base column name"/>
</property>
</class>`
`
所有持久类都必须有一个默认构造函数(可以是非公共的),以便Hibernate可以使用constructor.newInstance()实例化它们。建议在Hibernate中为运行时代理生成提供至少具有包可见性的默认构造函数。
可能重复。见本问题: