From 893fdd1c2700e8495866d21a7471b4722faeab6b Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Mon, 11 Nov 2024 11:57:15 +0100 Subject: [PATCH] HHH-18819 Add test for issue --- .../metamodel/EmbeddableMetaModelTest.java | 16 +++++++++++++ .../hibernate/orm/test/metamodel/Weight.java | 15 ++++++++++++ .../orm/test/metamodel/WeightClass.java | 24 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Weight.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/WeightClass.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/EmbeddableMetaModelTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/EmbeddableMetaModelTest.java index 8d53b74cdde9..d398cff4adfd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/EmbeddableMetaModelTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/EmbeddableMetaModelTest.java @@ -26,6 +26,8 @@ Person.class, Measurement.class, Height.class, + WeightClass.class, + Weight.class, } ) public class EmbeddableMetaModelTest { @Test @@ -60,4 +62,18 @@ public void test(EntityManagerFactoryScope scope) { assertNotNull( Measurement_.unit ); } ); } + + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-18819" ) + public void testIdClass(EntityManagerFactoryScope scope) { + scope.inTransaction( entityManager -> { + final EmbeddableDomainType embeddable = (EmbeddableDomainType) entityManager.getMetamodel() + .embeddable( Weight.class ); + assertNotNull( embeddable.getSuperType() ); + assertEquals( MAPPED_SUPERCLASS, embeddable.getSuperType().getPersistenceType() ); + assertEquals( Measurement.class, embeddable.getSuperType().getJavaType() ); + assertNotNull( Weight_.weight ); + assertNotNull( Measurement_.unit ); + } ); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Weight.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Weight.java new file mode 100644 index 000000000000..c5557314bbfc --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Weight.java @@ -0,0 +1,15 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.metamodel; + +import jakarta.persistence.Embeddable; + +/** + * @author Marco Belladelli + */ +@Embeddable +public class Weight extends Measurement { + private float weight; +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/WeightClass.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/WeightClass.java new file mode 100644 index 000000000000..18d313b405a1 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/WeightClass.java @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.metamodel; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.IdClass; + +/** + * @author Marco Belladelli + */ +@Entity +@IdClass(Weight.class) +public class WeightClass { + @Id + private String unit; + + @Id + private float weight; + + private String description; +}