[英]Mapping enum subtypes in Hibernate
I'm developing a Java application using Java 6 and Hibernate 3.6.9 library. 我正在使用Java 6和Hibernate 3.6.9库开发Java应用程序。 I want to create an enum which is closely related to a specific class, so I want to define it as part of that class: 我想创建一个与特定类紧密相关的枚举,因此我想将其定义为该类的一部分:
package org.mycompany.container;
public class Container{
public enum ContainerType{
SMALL,MEDIUM,BIG
}
private ContainerType _ContainerType;
private Integer _Id;
//Getter and setters
}
Then I want to map my container class in an Hibernate configuration file (I don't use annotations). 然后,我想将我的容器类映射到Hibernate配置文件中(我不使用注释)。 So I have this xml piece (the package of the class is specified at the beginning of the hibernate-mapping file): 因此,我有这个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>
However, Hibernate doesn't seem to recognize the ContainerType class and I get a ClassNotFoundException . 但是,Hibernate似乎无法识别ContainerType类,并且得到了ClassNotFoundException 。 I have done this several times having the enum as a separate class. 我已经做了几次将此枚举作为一个单独的类。
Any solution? 有什么办法吗? Pool your ideas. 汇集您的想法。
尝试这个 :
org.mycompany.container.Container$ContainerType
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.