简体   繁体   中英

Mapping enum subtypes in Hibernate

I'm developing a Java application using Java 6 and Hibernate 3.6.9 library. 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). So I have this xml piece (the package of the class is specified at the beginning of the hibernate-mapping file):

<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 . I have done this several times having the enum as a separate class.

Any solution? Pool your ideas.

尝试这个 :

org.mycompany.container.Container$ContainerType

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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