Thread:
 Adding solution to code base 
 Martin Kersten   04 May 2005, 03:18 
 and a mapping to int in the DB? 
 benoitx   15 Jul 2005, 19:20 
 Re: and a mapping to int in the DB? 
 benoitx   15 Jul 2005, 20:41 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: benoitx (15 Jul 2005, 19:20) Replies: 1, Views: 38185
Subject: and a mapping to int in the DB?
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
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]