Cara, você tem que usar um “conversor” Handler
[code]package br.com.aedas.athenas.core.dao.hibernate.enumHandle;
import java.io.Serializable;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
public abstract class AbstractEnumHandler<C extends Enum> implements UserType {
protected int dbType = 0; // Db type
protected Class<C> cClass = null; // Enum class.
public AbstractEnumHandler(Class<C> cClass, int dbType) {
this.cClass = cClass;
this.dbType = dbType;
}
public int[] sqlTypes() {
return new int[] { this.dbType };
}
/**
* @see UserType#returnedClass()
*/
public Class<C> returnedClass() {
return this.cClass;
}
/**
* @see UserType#deepCopy(Object)
*/
public Object deepCopy(Object value) throws HibernateException{
return value;
}
/**
* @see UserType#isMutable()
*/
public boolean isMutable() {
return false;
}
/**
* @see UserType#assemble(Serializable, Object)
*/
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return cached;
}
/**
* @see UserType#disassemble(Object)
*/
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable)value;
}
/**
* @see UserType#replace(Object, Object, Object)
*/
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
}
/**
* @see UserType#hashCode()
*/
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
/**
* @see UserType#equals(Object)
*/
public boolean equals(Object x, Object y) throws HibernateException {
return (x == y) && (null != x || null != y) && x.equals(y);
}
}
[/code]
[code]package br.com.aedas.athenas.core.dao.hibernate.enumHandle;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
public abstract class AbstractEnumToString<C extends Enum> extends AbstractEnumHandler {
/**
* Creates an enum handler to persist enum as String.
* @param cClass Enum class.
*/
protected AbstractEnumToString(Class<C> cClass) {
super(cClass, Types.VARCHAR);
}
/**
* @see UserType#nullSafeSet(java.sql.PreparedStatement, Object, int)
*/
public Object nullSafeGet(ResultSet rs, String[] names, Object arg2) throws HibernateException, SQLException {
String name = rs.getString(names[0]);
C result = null;
if (!rs.wasNull()) {
result = Enum.valueOf(cClass, name);
}
return result;
}
/**
* @see UserType#nullSafeSet(PreparedStatement, Object, int)
*/
@SuppressWarnings("unchecked")
public void nullSafeSet(PreparedStatement ps, Object value, int index) throws HibernateException, SQLException {
if (null == value) {
ps.setNull(index, this.dbType);
} else {
ps.setString(index, ((Enum)value).name());
}
}
}[/code]
Espero que vc entenda