[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5188) Use provided enum type ordinal/string when reading

Stefan Larsson (JIRA) noreply at atlassian.com
Mon May 3 18:44:22 EDT 2010


Use provided enum type ordinal/string when reading
--------------------------------------------------

                 Key: HHH-5188
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5188
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.5.1, 3.5.0-CR-2
            Reporter: Stefan Larsson
            Priority: Minor
         Attachments: EnumType.java-typeSafeNullSafeGet.patch

When Hibernate reads a PostgreSQL enum type using ResultSet.getObject(), the JDBC driver returns a driver-specific PGObject object, which preserves both the value of the enum and its type ordinal/string. Hibernate fails with a ClassCastException when it attempts to cast the PGObject into a String in org.hibernate.type.EnumType.nullSafeGet().

The code in org.hibernate.type.EnumType assumes that ResultSet.getObject() will either return a Number or a String, which is not true for the PostgreSQL driver. IMHO it would be better to let the JDBC driver do the conversion using ResultSet.getInt() or getString() instead.

The attached patch allows JBoss AS 6 M3 (Hibernate 3.5.0-CR-2) to read PostgreSQL enums, using JPA, with a a Java enum annotated as @javax.persistence.Enumerated(javax.persistence.EnumType.STRING).

Also, I believe that perhaps ignoring the given enum type causes Issue HHH-4230, where an ordinal enum was stored in character field. ResultSet.getInteger() might work for that one depending on the JDBC driver.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list