繁体   English   中英

映射hibernate hbm中的枚举?

[英]Mapping an enum in 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;
    }


}

我需要保存整数值而不是一个和两个。 我怎样才能做到这一点? 我在我的hbm中有以下配置:

<property name="action">
            <column name="ACTION" />
            <type name="org.hibernate.type.EnumType">
                <param name="enumClass">com.ExampleEnum</param>
            </type>
        </property> 

我是否需要任何其他配置来保存整数? 请帮我!

谢谢!

`

<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>`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM