Criteria on Enum mapping defined in hbm.xml fails.
Description
Activity
Steve EbersoleJuly 20, 2015 at 5:36 PM
https://hibernate.atlassian.net/browse/HHH-9955#icft=HHH-9955 is the Jira I created for the discussion.
Steve EbersoleJuly 20, 2015 at 5:15 PM
For those interested.. there is a discussion on the hibernate-dev mailing list currently about removing this ability to dynamically determine "enum type" (named v. ordinal) during nullSafeSet/nullSafeGet (aka using JDBC metadata). We have seen too many cases where this is problematic against too many JDBC drivers not properly implementing java.sql.ParameterMetaData#getParameterType
and/or java.sql.ResultSetMetaData#getColumnType
.
The mapping above would still work according to the proposal, for what its worth.
Daniel NußSeptember 6, 2013 at 3:08 PM
We just discovered exactly this problem, too (with mysql and both Hibernate 4.2.0.Final and within Jboss EAP 6.1.0 with contained Hibernate 'hibernate-core-4.2.0.Final-redhat-1.jar') . As the fixing of this issue would be quite urgent to us: Is there any chance that this is going to be solved soon? Is there a known workaround?
The obvious workaround to use ordinals for enums is no option for us, we want the literal values of enums to be saved in the database.
More detailed error description (at least as far i understand it):
The problem occurs when trying to resolve the enum mapper in EnumType.resolveEnumValueMapper while trying to save an enum value. There the expression 'rs.getMetaData().getColumnType( rs.findColumn( name ) ) ' leads to the exception 'java.sql.SQLException: Parameter metadata not available for the given statement', and so the fallback strategy is being used, which saves the given enum value as ordinal in the database. But, when trying to load the same value from database, the value is resolved correctly (to 12) and therefore the correct enum mapper is being used - which then tries to interpret the given ordinal as a literal, which (obviously) fails.
In JBoss it happens exactly the other way round (a literal was saved in the database but the EnumMapper tries to read a ordinal value from the database when reading the enum value).
miguel.ruiz@jemmic.comAugust 30, 2013 at 8:09 AM
It also doesn't work in 4.2.2
Marco JancAugust 26, 2013 at 1:59 AM
Still not working in 4.2.4 Final
Using Hibernate 4.1.4 mapping String Enum's via hbm.xml annotation files worked.
Updating to 4.2 final and 4.3.0.Beta1 makes it no longer work.
Using any filtering on an Enum like 'Restrictions.eq("type", EnumTest.VALUE)'
and a mapping of:
<property name="type" column="type" not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">default.EnumTest</param>
<param name="type">12</param>
</type>
</property>