在 HBM 中添加枚举作为类属性 [英] Adding an enum as a class property in HBM

查看:41
本文介绍了在 HBM 中添加枚举作为类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 HBM 文件中创建一个类,其中包含一个 Enum 作为字段.

I am trying to create a class in HBM file which contains an Enum as a field.

HBM 与此类似:

<class name="a.b.c.myObject" table="OBJECT" >
       <property name="myEnum" column="EXAMPLE" type="a.b.c.myEnum" />
</class>

假设这是枚举:

public enum myEnum{
    a, b, c;
}

问题在于,在数据库中,我希望看到该枚举的字符串值(a、b 或 c),但我得到了该字段的原始数据.

The problem is that in the DB I expected to see the String value of that enum (a,b or c) but instead I got the raw data of that field.

我该如何解决?

推荐答案

这里是 Hibernate 3.6.x 的解决方案:

Here is the solution with Hibernate 3.6.x :

<class name="a.b.c.myObject" table="OBJECT">
  <property name="myEnum" column="EXAMPLE">
    <type name="org.hibernate.type.EnumType">
      <param name="enumClass">a.b.c.myEnum</param>
    </type>       
  </property>
</class>

这篇关于在 HBM 中添加枚举作为类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆