Aritz
Aritz

Reputation: 31649

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.

Upvotes: 0

Views: 249

Answers (1)

srikanth yaradla
srikanth yaradla

Reputation: 1235

Try this :

org.mycompany.container.Container$ContainerType

Upvotes: 1

Related Questions