jdk1.5推出的enum类型,在hibernate中一般是用注释做映射,这也是配合1.5提供的注释功能。 但是如果要把enum类型映射到传统的xml配置文件中,怎么办? 找到一种比较简单的方法。
<property name="type" column="note_type" length="10"> <type name="org.hibernate.type.EnumType"> <param name="enumClass">com.mycomp.modulename.MyEnum</param> <param name="type">12</param> </type> </property>
org.hibernate.type.EnumType是hibernate-anotations.jar包中的类。 下面的类就是你需要映射的类。这样就省了你需要自己写的hibernate类型。 下面的12应该是保存为int型的意思吧。这个需要看下源代码。。。。。