On 04 May 2005 03:18, Martin Kersten wrote:
>The code looks very good. I wonder if this code can be placed into the
>normal distribution. I found only three implementors of the UserType
>interface and saidly this wasn't in there.
Would be great indeed! This is the kind of code that one does not want
to see duplicated...
Has anyone managed to do something equivalent for a mapping to an int?
ie the ordinal may be?
Saving to the database is no issue but there are no equivalent to
Enum.valueOf(int...) and for some reason that I do not quite understand,
values() is not a method on Enum... How would one pass the enum to the
EnumUserType?
The problem is in
public Object nullSafeGet(ResultSet resultSet, String[] names,
Object owner)
throws HibernateException, SQLException {
Integer val = resultSet.getInt(names[0]);
E result = null;
if (!resultSet.wasNull()) {
for(E e : ****Class<E>****.values()) {
if (e.ordinal() == val) {
return e;
}
}
}
return result;
}
How can we access .values()???
Any suggestion or solution?
Thanks
Benoit |