Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在hibernate hbm中映射枚举?_Java_Hibernate - Fatal编程技术网

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中为运行时代理生成提供至少具有包可见性的默认构造函数。
可能重复。见本问题: