HHH-18202 Add test for issue

This commit is contained in:
Marco Belladelli 2024-05-31 10:58:31 +02:00 committed by Christian Beikov
parent c33ccc09dc
commit 7066861147
1 changed files with 37 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
} ) } )
@SessionFactory @SessionFactory
@Jira( "https://hibernate.atlassian.net/browse/HHH-17837" ) @Jira( "https://hibernate.atlassian.net/browse/HHH-17837" )
@Jira( "https://hibernate.atlassian.net/browse/HHH-18202" )
public class ManyToManyGroupByOrderByTest { public class ManyToManyGroupByOrderByTest {
@Test @Test
public void testSelectEntity(SessionFactoryScope scope) { public void testSelectEntity(SessionFactoryScope scope) {
@ -110,6 +111,42 @@ public class ManyToManyGroupByOrderByTest {
} ); } );
} }
@Test
public void testDistinctAndAggregates(SessionFactoryScope scope) {
// explicit join distinct
scope.inTransaction( session -> {
final Tuple result = session.createQuery(
"select distinct owner.id from Cat cat join cat.owners owner group by owner.id order by owner.id",
Tuple.class
).getSingleResult();
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
} );
// explicit join distinct + aggregate
scope.inTransaction( session -> {
final Tuple result = session.createQuery(
"select distinct min(owner.id), cat.id from Cat cat join cat.owners owner group by cat.id order by min(owner.id), cat.id",
Tuple.class
).getSingleResult();
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
} );
// implicit join distinct
scope.inTransaction( session -> {
final Tuple result = session.createQuery(
"select distinct element(cat.owners).id from Cat cat group by element(cat.owners).id order by element(cat.owners).id",
Tuple.class
).getSingleResult();
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
} );
// implicit join distinct + aggregate
scope.inTransaction( session -> {
final Tuple result = session.createQuery(
"select distinct min(element(cat.owners).id), cat.id from Cat cat group by cat.id order by min(element(cat.owners).id), cat.id",
Tuple.class
).getSingleResult();
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
} );
}
@BeforeAll @BeforeAll
public void setUp(SessionFactoryScope scope) { public void setUp(SessionFactoryScope scope) {
scope.inTransaction( session -> { scope.inTransaction( session -> {