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
rs.getString()
instead? It should return the enum value as a String, AFAIK. – JB Nizet Mar 7 at 22:51