我正在使用 Java 6 和 Hibernate 3.6.9 库开发 Java 应用程序。我想创建一个与特定类密切相关的枚举,因此我想将其定义为该类的一部分:
package org.mycompany.container;
public class Container{
public enum ContainerType{
SMALL,MEDIUM,BIG
}
private ContainerType _ContainerType;
private Integer _Id;
//Getter and setters
}
然后我想在 Hibernate 配置文件中映射我的容器类(我不使用注释)。所以我有这个 xml 片段(类的包在 hibernate-mapping 文件的开头指定):
<class name="Container" table="tcontainer">
<id name="_Id" column="id">
<generator class="increment" />
</id>
<property name="_ContainerType" column="container_type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.mycompany.container.Container.ContainerType</param>
<param name="type">12</param>
</type>
</property>
</class>
但是,Hibernate 似乎无法识别 ContainerType 类,并且我收到 ClassNotFoundException。我已经多次这样做了,将enum作为一个单独的类。
有什么解决办法吗?汇集您的想法。
最佳答案
试试这个:
org.mycompany.container.Container$ContainerType
关于java - 在 Hibernate 中映射枚举子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16807853/