From 5a89c3412756daaa02b901004f7b18896236ba89 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 5 Dec 2022 13:14:15 +0100 Subject: [PATCH] HHH-15744 Add test for issue --- .../polymorphic/PolymorphicQueriesTest2.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest2.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest2.java b/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest2.java new file mode 100644 index 0000000000..9075621609 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest2.java @@ -0,0 +1,74 @@ +package org.hibernate.orm.test.polymorphic; + +import org.hibernate.query.spi.QueryImplementor; + +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.BeforeAll; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + +@DomainModel( + annotatedClasses = PolymorphicQueriesTest2.Human.class +) +@SessionFactory +@TestForIssue( jiraKey = "HHH-15744") +public class PolymorphicQueriesTest2 { + + + @BeforeAll + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + session.persist( new Human( "Fab" ) ); + } + ); + } + + @Test + public void testQuery(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + QueryImplementor query = session.createQuery( + "from org.hibernate.orm.test.polymorphic.PolymorphicQueriesTest2$Animal u where (u.name = ?1)", + Animal.class + ); + query.setParameter( 1, "Fab" ); + query.list(); + } + ); + } + + public interface Animal { + String getName(); + } + + @Entity(name = "Human") + public static class Human implements Animal { + @Id + @GeneratedValue + private Long id; + private String name; + + public Human() { + } + + public Human(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + @Override + public String getName() { + return name; + } + } +}