Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to have a enum type on the database and convert it to java, I wrote a EnumUserType class to do the conversion, but it doesn't recognize the PGobject class.

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor si, Object owner)
        throws HibernateException, SQLException {
    Object object = rs.getObject(names[0]);
    if (rs.wasNull()) {
        return null;
    }

    if (object instanceof PGobject) {
        //code doesn't reach this line
    }

    log.info(object.getClass()); // prints class org.postgresql.util.PGobject
    return null;
}

I checked and I have the exact same postgresql driver version. I saw this post: Java enum with Eclipselink. It is a solution that I will also try, but my main question is: apparently it is the same class, why it is not being recognized as such? Can I have two different classes with the same name and package? If I still have to use enums in Postgres, how can I fix it to properly map to my Java enum?

EDIT:

I tried to do a:

PGobject pg = (PGobject) object;

and it throws a class cast exception:

org.postgresql.util.PGobject cannot be cast to org.postgresql.util.PGobject

Thanks

share|improve this question
2  
Why don't you use rs.getString() instead? It should return the enum value as a String, AFAIK. –  JB Nizet Mar 7 at 22:51
 
Just tried it and it throws an exception: org.postgresql.util.PGobject cannot be cast to java.lang.String –  Migore Mar 8 at 12:37
 
Disregard my previous comment, there was something else missing. Just tried it and it work, thanks! This solve my issue but I'm still curious about the problem. –  Migore Mar 8 at 12:56
1  
Judging by the exception, it looks like a classloader problem - the same class loaded by two different classloaders are considered different classes by java. –  Grim Mar 8 at 13:18
 
I'm using JBoss AS 7.1.1 as a container, I copied the same jar to jboss repository and to my local maven repository that is used by my application. –  Migore Mar 8 at 13:43
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.