From b39c52b4d90617bfc8658eb50bc849518dd17d6b Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Thu, 26 Jan 2023 22:53:12 +0100 Subject: [PATCH] HHH-4299 - Add test for issue Signed-off-by: Jan Schatteman --- ...bleWithGenericAndMappedSuperClassTest.java | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/EmbeddableWithGenericAndMappedSuperClassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/EmbeddableWithGenericAndMappedSuperClassTest.java index 8eed5606577..e91746183fb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/EmbeddableWithGenericAndMappedSuperClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/EmbeddableWithGenericAndMappedSuperClassTest.java @@ -2,15 +2,18 @@ import java.util.List; +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.BeforeEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.Embeddable; +import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Inheritance; @@ -22,7 +25,8 @@ @DomainModel( annotatedClasses = { EmbeddableWithGenericAndMappedSuperClassTest.PopularBook.class, - EmbeddableWithGenericAndMappedSuperClassTest.RareBook.class + EmbeddableWithGenericAndMappedSuperClassTest.RareBook.class, + EmbeddableWithGenericAndMappedSuperClassTest.GenericExample.class } ) @SessionFactory @@ -33,7 +37,7 @@ public class EmbeddableWithGenericAndMappedSuperClassTest { private final static long RARE_BOOK_ID = 2l; private final static Integer RARE_BOOK_CODE = 123; - @BeforeEach + @BeforeAll public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { @@ -45,6 +49,19 @@ public void setUp(SessionFactoryScope scope) { session.persist( popularBook ); session.persist( rareBook ); + + session.persist( new GenericExample(1, new Range<>(2, 3)) ); + } + ); + } + + @AfterAll + public void tearDown(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + session.createMutationQuery( "delete from PopularBook" ).executeUpdate(); + session.createMutationQuery( "delete from RareBook" ).executeUpdate(); + session.createMutationQuery( "delete from GenericExample" ).executeUpdate(); } ); } @@ -108,6 +125,48 @@ public void test(SessionFactoryScope scope) { ); } + @Test + @TestForIssue(jiraKey = "HHH-4299") + public void testGenericEmbeddedAttribute(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + GenericExample ge = session.get( GenericExample.class, 1 ); + assertThat( ge ).isNotNull(); + assertThat( ge ).extracting( "bounds" ).isNotNull(); + } + ); + } + + @Entity(name = "GenericExample") + public static class GenericExample { + @Id + private int id; + @Embedded + private Range bounds; + + public GenericExample() { + } + + public GenericExample(int id, Range bounds) { + this.id = id; + this.bounds = bounds; + } + } + + public static class Range { + + private T minimum; + private T maximum; + + public Range() { + } + + public Range(T minimum, T maximum) { + this.minimum = minimum; + this.maximum = maximum; + } + } + @Embeddable public static class Edition { private String editorName;