[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5188) Use provided enum type ordinal/string when reading
Stefan Larsson (JIRA)
noreply at atlassian.com
Tue Jan 11 18:25:06 EST 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39582#action_39582 ]
Stefan Larsson commented on HHH-5188:
-------------------------------------
Yes, when running the software with JBoss AS 6.0.0.Final which bundles hibernate 3.6, it still tries to cast a PGObject to a String:
{noformat}
Caused by: java.lang.ClassCastException: org.postgresql.util.PGobject cannot be cast to java.lang.String
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:120) [:3.6.0.Final]
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:109) [:3.6.0.Final]
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:104) [:3.6.0.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2265) [:3.6.0.Final]
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1527) [:3.6.0.Final]
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1455) [:3.6.0.Final]
at org.hibernate.loader.Loader.getRow(Loader.java:1355) [:3.6.0.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611) [:3.6.0.Final]
...
{noformat}
> 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.0-CR-2, 3.5.1
> 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