From 39f78c89fda5dc51e20268ea18f59bd86aae1d60 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 19 Nov 2024 10:36:10 +0100 Subject: [PATCH] HHH-18862 Add test for issue --- .../EntityValuedPathsGroupByOrderByTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/EntityValuedPathsGroupByOrderByTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/EntityValuedPathsGroupByOrderByTest.java index ee82eaebd3..ebbf53b4c3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/EntityValuedPathsGroupByOrderByTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/EntityValuedPathsGroupByOrderByTest.java @@ -188,6 +188,35 @@ public class EntityValuedPathsGroupByOrderByTest { ).getResultList() ).hasSize( 2 ) ); } + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-18862" ) + public void testSubquerySelectionGroupBy(SessionFactoryScope scope) { + scope.inTransaction( session -> assertThat( session.createQuery( + "select (select s.id from EntityB ignore) from EntityA a join a.secondary s group by s.id", + Long.class + ).getSingleResult() ).isEqualTo( 1L ) ); + } + + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-18862" ) + public void testSubquerySelectionGroupByAndOrderBy(SessionFactoryScope scope) { + scope.inTransaction( session -> assertThat( session.createQuery( + "select (select s.id from EntityB ignore) from EntityA a" + + " join a.secondary s group by s.id order by s.id", + Long.class + ).getSingleResult() ).isEqualTo( 1L ) ); + } + + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-18862" ) + public void testSubquerySelectionGroupByAndOrderByImplicit(SessionFactoryScope scope) { + scope.inTransaction( session -> assertThat( session.createQuery( + "select (select a.secondary.id from EntityB ignore) from EntityA a" + + " group by a.secondary.id order by a.secondary.id", + Long.class + ).getSingleResult() ).isEqualTo( 1L ) ); + } + @Entity( name = "EntityA" ) public static class EntityA { @Id