if you want to store the Enum type with int,you can:
public Object nullSafeGet(ResultSet resultSet, String[] names,
Object owner)
throws HibernateException, SQLException {
Object result = null;
try {
int index = resultSet.getInt(names[0]);
if (!resultSet.wasNull()) {
Object[] enumValue = enumValues.get(this.getClass());
if (enumValue == null) {
Method method = null;
method = clazz.getDeclaredMethod("values", new
Class[0]);
enumValue = (Object[]) method.invoke(null, new
Object[0]);
enumValues.put(this.getClass(), enumValue);
}
result = enumValue[index];
}
} catch (Exception e) {
e.printStackTrace();
result = null;
}
return result;
}
public void nullSafeSet(PreparedStatement preparedStatement,
Object value,
int index) throws HibernateException, SQLException {
if (null == value) {
preparedStatement.setNull(index, Types.VARCHAR);
} else {
preparedStatement.setInt(index, ((Enum) value).ordinal());
}
} |