Hello,
I’m trying to prepare the migration of an application written with Hibernate 3 (currently using Hibernate 5.5) that has a lot of .hbm.xml mappings.
In order to map enums by name (instead of the default by ordinal) it is configured this way:
Example hbm.xml file:
<hibernate-mapping package="x.y.z">
<typedef name="exampleEnumType" class="x.y.z.EnumUserType">
<param name="enumClass">x.y.z.ExampleEnum</param>
</typedef>
...
<property name="..." type="exampleEnumType"/>
And our custom EnumUserType overrides the parameters to force the use of NamedEnumValueConverter:
import java.util.Properties;
import org.hibernate.type.EnumType;
public class EnumUserType<T extends Enum<T>> extends EnumType<T> {
@Override
public void setParameterValues(Properties parameters) {
parameters.setProperty(EnumType.NAMED, "true");
super.setParameterValues(parameters);
}
}
This works fine with Hibernate 5 but when moving to 6.0.0 Alpha 9 only one instance of that EnumUserType ever seems to be created by Hibernate, even though there are multiple typedef
in multiple hbm files. That instance is configured multiple times and in the end keeps the last enumClass. Then when the type is used in a query the wrong enum is used and the data fails to load.
In debug I was able to confirm that the EnumUserType.setParameterValues()
method is always called on the same instance.
Could you please advise if that’s an incorrect/unsupported way to map enums by name (using hbm) or if that’s a bug in the new type system?