HHH-14820 - Customized EnumType not working with hbm mapping in Hibernate 6 (Reproducer)
A simple unit test illustrating issue HHH-14820 : since Hibernate ORM 6 the custom NamedEnumUserType is only instantiated once (while there are two enums configured with this type)
This commit is contained in:
parent
d8b984ed7f
commit
bef0554eb7
|
@ -0,0 +1,21 @@
|
|||
package org.hibernate.orm.test.mapping.converted.enums;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.type.EnumType;
|
||||
|
||||
/**
|
||||
* A simple user type where we force enums to be saved by name, not ordinal
|
||||
*
|
||||
* @author gtoison
|
||||
*/
|
||||
public class NamedEnumUserType<T extends Enum<T>> extends EnumType<T> {
|
||||
private static final long serialVersionUID = -4176945793071035928L;
|
||||
|
||||
@Override
|
||||
public void setParameterValues(Properties parameters) {
|
||||
parameters.setProperty(EnumType.NAMED, "true");
|
||||
|
||||
super.setParameterValues(parameters);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.hibernate.orm.test.mapping.converted.enums;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author gtoison
|
||||
*
|
||||
*/
|
||||
public class NamedEnumUserTypeTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "org/hibernate/orm/test/mapping/converted/enums/PersonNamedEnumsUserType.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTest() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
s.persist( Person.person( Gender.MALE, HairColor.BLACK ) );
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-14820")
|
||||
public void testNamedEnumUserType() {
|
||||
// This fails because the same instance of NamedEnumUserType is used for both enums
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
s.createQuery( "from Person p", Person.class );
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping>
|
||||
<typedef name="gender" class="org.hibernate.orm.test.mapping.converted.enums.NamedEnumUserType">
|
||||
<param name="enumClass">org.hibernate.orm.test.mapping.converted.enums.Gender</param>
|
||||
</typedef>
|
||||
<typedef name="hairColor" class="org.hibernate.orm.test.mapping.converted.enums.NamedEnumUserType">
|
||||
<param name="enumClass">org.hibernate.orm.test.mapping.converted.enums.HairColor</param>
|
||||
</typedef>
|
||||
|
||||
<class name="org.hibernate.orm.test.mapping.converted.enums.Person">
|
||||
<id name="id" type="long">
|
||||
<generator class="native"></generator>
|
||||
</id>
|
||||
|
||||
<property name="gender" not-null="true" type="gender"/>
|
||||
<property name="hairColor" not-null="true" type="hairColor"/>
|
||||
<property name="originalHairColor" type="hairColor"/>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue