MySql database came's with an enum datatype that although is quite proprietery it can be easily mapped to a java enumeration type in hibernate.

In our example consider the case were we have created a table SIZES which contains a colum SIZE that is declared as enum type with values SMALL, MEDIUM and LARGE. Firstly we create the database table:

CREATE TABLE IF NOT EXISTS `sizes` (
  `id` int(10) NOT NULL DEFAULT '0',
  `size` enum('MEDIUM','LARGE','SMALL') DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


INSERT INTO `sizes` (`id`, `size`) VALUES
	(0, 'SMALL');

The next step is to create the java enum type Size and the Sizes pojo class


package com.javaonly.model;



public enum Size {

    LARGE("LARGE"), MEDIUM("MEDIUM"), SMALL("SMALL");
    String name;

    Size(String name) {
        this.name = name;
    }

    public String toString() {
        return name;
    }
}

package com.javaonly.model;

public class Sizes {
    private int idl;
    private Size size;

    /**
     * @return the idl
     */
    public int getIdl() {
        return idl;
    }

    /**
     * @param idl the idl to set
     */
    public void setIdl(int idl) {
        this.idl = idl;
    }

    /**
     * @return the size
     */
    public Size getSize() {
        return size;
    }

    /**
     * @param size the size to set
     */
    public void setSize(Size size) {
        this.size = size;
    }
    public String toString(){
        return size.toString();
    }
}

Finally we create the hibernate mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.javaonly.model.Sizes" table="sizes">
        <id name="idl" type="integer" column="id">
            <generator class="native"/>    
        </id>
        <property name="size" column="size">
            <type name="org.hibernate.type.EnumType">
                <param name="enumClass">com.javaonly.model.Size</param>
            </type>    
        </property>
    </class>
</hibernate-mapping>

The important part  in the hibernate mapping file is the declaration of the property type.Hibernate comes with a class that represents the java enum type that  -among the other parameters- takes as a parameter the enumeration class which in this case is the com.javaonly.model.Size class