From bc94357d4ab2bd701dcab425487acd9d7a95e280 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 8 Aug 2022 17:26:00 +0200 Subject: [PATCH] HHH-15442 Add test for issue --- .../orm/test/any/annotations/AnyTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyTest.java index 3f34f50707..2c01a44c68 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/any/annotations/AnyTest.java @@ -159,6 +159,38 @@ public class AnyTest { ); } + @Test + @TestForIssue( jiraKey = "HHH-15442") + public void testHqlCollectionTypeQueryWithParameters(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + List propertySets = session.createQuery( + "select p from PropertySet p where type(p.generalProperties) = :prop ", + PropertySet.class ) + .setParameter( "prop", IntegerProperty.class) + .list(); + assertEquals( 1, propertySets.size() ); + + PropertySet propertySet = propertySets.get( 0 ); + assertEquals( 1, propertySet.getGeneralProperties().size() ); + + assertEquals( "age", propertySet.getGeneralProperties().get( 0 ).getName() ); + + propertySets = session.createQuery( + "select p from PropertySet p where type(p.generalProperties) = :prop ", + PropertySet.class ) + .setParameter( "prop", StringProperty.class) + .list(); + assertEquals( 1, propertySets.size() ); + + propertySet = propertySets.get( 0 ); + assertEquals( 1, propertySet.getGeneralProperties().size() ); + + assertEquals( "name", propertySet.getGeneralProperties().get( 0 ).getName() ); + } + ); + } + @Test @TestForIssue( jiraKey = "HHH-15323") public void testHqlTypeQuery(SessionFactoryScope scope) { @@ -181,6 +213,33 @@ public class AnyTest { ); } + + @Test + @TestForIssue( jiraKey = "HHH-15442") + public void testHqlTypeQueryWithParameter(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + List propertyHolders = session.createQuery( + "select p from PropertyHolder p where type(p.property) = :prop ", + PropertyHolder.class ) + .setParameter( "prop", IntegerProperty.class) + .list(); + assertEquals( 1, propertyHolders.size() ); + + assertEquals( "age", propertyHolders.get( 0 ).getProperty().getName() ); + + propertyHolders = session.createQuery( + "select p from PropertyHolder p where type(p.property) = :prop ", + PropertyHolder.class ) + .setParameter( "prop", StringProperty.class) + .list(); + assertEquals( 1, propertyHolders.size() ); + + assertEquals( "name", propertyHolders.get( 0 ).getProperty().getName() ); + } + ); + } + @Test public void testDefaultAnyAssociation(SessionFactoryScope scope) { scope.inTransaction(