diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java b/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java index 6972b44f26..6e446ea5e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/TypeDefinition.java @@ -102,7 +102,7 @@ public class TypeDefinition implements Serializable { if ( CollectionHelper.isEmpty( localConfigParameters ) ) { // we can use the re-usable resolution... if ( reusableResolution == null ) { - reusableResolution = createResolution( null, Collections.emptyMap(), indicators, context ); + reusableResolution = createResolution( name, Collections.emptyMap(), indicators, context ); } return reusableResolution; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/enums/NamedEnumUserTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/enums/NamedEnumUserTypeTest.java deleted file mode 100644 index ca72d826dc..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/enums/NamedEnumUserTypeTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * - */ -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 ); - } ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/enums/NamedEnumUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/NamedEnumUserType.java similarity index 62% rename from hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/enums/NamedEnumUserType.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/NamedEnumUserType.java index c75b73647d..44bb568f0d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/enums/NamedEnumUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/NamedEnumUserType.java @@ -1,21 +1,27 @@ -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> extends EnumType { - private static final long serialVersionUID = -4176945793071035928L; - - @Override - public void setParameterValues(Properties parameters) { - parameters.setProperty(EnumType.NAMED, "true"); - - super.setParameterValues(parameters); - } +/* + * 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 + */ +package org.hibernate.orm.test.mapping.type.custom.typedef; + +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> extends EnumType { + private static final long serialVersionUID = -4176945793071035928L; + + @Override + public void setParameterValues(Properties parameters) { + parameters.setProperty(EnumType.NAMED, "true"); + + super.setParameterValues(parameters); + } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/NamedEnumUserTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/NamedEnumUserTypeTest.java new file mode 100644 index 0000000000..bcf7617a91 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/NamedEnumUserTypeTest.java @@ -0,0 +1,61 @@ +/* + * 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 + */ + +/** + * + */ +package org.hibernate.orm.test.mapping.type.custom.typedef; + +import org.hibernate.orm.test.mapping.converted.enums.Gender; +import org.hibernate.orm.test.mapping.converted.enums.HairColor; +import org.hibernate.orm.test.mapping.converted.enums.Person; + +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests that the same UserType class used in multiple distinct TypeDefinitions + * get distinct ManagedBeans. + * + * NOTE : this is with no local parameter + * + * @author gtoison + */ +@DomainModel( + xmlMappings = "mappings/type/custom/typedef/PersonNamedEnumsUserType.xml" +) +@SessionFactory +public class NamedEnumUserTypeTest { + @Test + @TestForIssue(jiraKey = "HHH-14820") + public void testNamedEnumUserType(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + session.createQuery( "from Person p", Person.class ).list(); + } ); + } + + @BeforeEach + public void createTestData(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + session.persist( Person.person( Gender.MALE, HairColor.BLACK ) ); + } ); + } + + @AfterEach + public void dropTestData(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + session.createQuery( "delete Person" ).executeUpdate(); + } ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/package-info.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/package-info.java new file mode 100644 index 0000000000..1d9c491a67 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/custom/typedef/package-info.java @@ -0,0 +1,13 @@ +/* + * 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 + */ + +/** + * Tests for {@code } definitions in {@code hbm.xml} mappings + * + * @author Steve Ebersole + */ +package org.hibernate.orm.test.mapping.type.custom.typedef; \ No newline at end of file diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/PersonNamedEnumsUserType.xml b/hibernate-core/src/test/resources/mappings/type/custom/typedef/PersonNamedEnumsUserType.xml similarity index 79% rename from hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/PersonNamedEnumsUserType.xml rename to hibernate-core/src/test/resources/mappings/type/custom/typedef/PersonNamedEnumsUserType.xml index a0670839c4..a1be658a0d 100644 --- a/hibernate-core/src/test/resources/org/hibernate/orm/test/mapping/converted/enums/PersonNamedEnumsUserType.xml +++ b/hibernate-core/src/test/resources/mappings/type/custom/typedef/PersonNamedEnumsUserType.xml @@ -2,18 +2,18 @@ - + org.hibernate.orm.test.mapping.converted.enums.Gender - + org.hibernate.orm.test.mapping.converted.enums.HairColor