HHH-18202 Add test for issue
This commit is contained in:
parent
da22678c74
commit
01199d2c1f
|
@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
} )
|
||||
@SessionFactory
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-17837" )
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-18202" )
|
||||
public class ManyToManyGroupByOrderByTest {
|
||||
@Test
|
||||
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
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
|
|
Loading…
Reference in New Issue