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 6a222ae003..7ae21c5c87 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 @@ -7,27 +7,31 @@ package org.hibernate.orm.test.metamodel; -import org.hibernate.testing.TestForIssue; +import org.hibernate.metamodel.model.domain.EmbeddableDomainType; + import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.Jpa; import org.junit.jupiter.api.Test; +import static jakarta.persistence.metamodel.Type.PersistenceType.MAPPED_SUPERCLASS; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -@Jpa( - annotatedClasses = { - ProductEntity.class, - Person.class, - Company.class - } -) +@Jpa( annotatedClasses = { + ProductEntity.class, + LocalizedValue.class, + Company.class, + Address.class, + Person.class, + Measurement.class, + Height.class, +} ) public class EmbeddableMetaModelTest { - @Test - @TestForIssue(jiraKey = "HHH-11111") + @Jira( "https://hibernate.atlassian.net/browse/HHH-11111" ) public void testEmbeddableCanBeResolvedWhenUsedAsInterface(EntityManagerFactoryScope scope) { scope.inTransaction( entityManager -> { assertNotNull( entityManager.getMetamodel().embeddable( LocalizedValue.class ) ); @@ -36,13 +40,26 @@ public class EmbeddableMetaModelTest { } ); } - @Test - @TestForIssue(jiraKey = "HHH-12124") + @Jira( "https://hibernate.atlassian.net/browse/HHH-12124" ) public void testEmbeddableEquality(EntityManagerFactoryScope scope) { scope.inTransaction( entityManager -> { assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Company_.address.getType() ) ); - assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Person_.address.getType() ) ); + assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Person_.height.getType() ) ); + } ); + } + + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-18103" ) + public void test(EntityManagerFactoryScope scope) { + scope.inTransaction( entityManager -> { + final EmbeddableDomainType embeddable = (EmbeddableDomainType) entityManager.getMetamodel() + .embeddable( Height.class ); + assertNotNull( embeddable.getSuperType() ); + assertEquals( MAPPED_SUPERCLASS, embeddable.getSuperType().getPersistenceType() ); + assertEquals( Measurement.class, embeddable.getSuperType().getJavaType() ); + assertNotNull( Height_.height ); + assertNotNull( Measurement_.unit ); } ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Height.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Height.java new file mode 100644 index 0000000000..ad41f901fd --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Height.java @@ -0,0 +1,17 @@ +/* + * 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.metamodel; + +import jakarta.persistence.Embeddable; + +/** + * @author Marco Belladelli + */ +@Embeddable +public class Height extends Measurement { + private float height; +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Measurement.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Measurement.java new file mode 100644 index 0000000000..c84421fb17 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Measurement.java @@ -0,0 +1,25 @@ +/* + * 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.metamodel; + +import jakarta.persistence.MappedSuperclass; + +/** + * @author Marco Belladelli + */ +@MappedSuperclass +public abstract class Measurement { + private String unit; + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Person.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Person.java index 0d1f538a7a..24e7d74a12 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Person.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/Person.java @@ -23,7 +23,7 @@ public class Person implements Serializable { private String name; @Embedded - private Address address = new Address(); + private Height height; public long getId() { return id; @@ -41,11 +41,11 @@ public class Person implements Serializable { this.name = name; } - public Address getAddress() { - return address; + public Height getHeight() { + return height; } - public void setAddress(Address address) { - this.address = address; + public void setHeight(Height height) { + this.height = height; } }