Skip to content

Commit 7066861

Browse files
mbladelbeikov
authored andcommitted
HHH-18202 Add test for issue
1 parent c33ccc0 commit 7066861

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/query/ManyToManyGroupByOrderByTest.java

+37
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
} )
3636
@SessionFactory
3737
@Jira( "https://hibernate.atlassian.net/browse/HHH-17837" )
38+
@Jira( "https://hibernate.atlassian.net/browse/HHH-18202" )
3839
public class ManyToManyGroupByOrderByTest {
3940
@Test
4041
public void testSelectEntity(SessionFactoryScope scope) {
@@ -110,6 +111,42 @@ public void testSelectAssociationId(SessionFactoryScope scope) {
110111
} );
111112
}
112113

114+
@Test
115+
public void testDistinctAndAggregates(SessionFactoryScope scope) {
116+
// explicit join distinct
117+
scope.inTransaction( session -> {
118+
final Tuple result = session.createQuery(
119+
"select distinct owner.id from Cat cat join cat.owners owner group by owner.id order by owner.id",
120+
Tuple.class
121+
).getSingleResult();
122+
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
123+
} );
124+
// explicit join distinct + aggregate
125+
scope.inTransaction( session -> {
126+
final Tuple result = session.createQuery(
127+
"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",
128+
Tuple.class
129+
).getSingleResult();
130+
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
131+
} );
132+
// implicit join distinct
133+
scope.inTransaction( session -> {
134+
final Tuple result = session.createQuery(
135+
"select distinct element(cat.owners).id from Cat cat group by element(cat.owners).id order by element(cat.owners).id",
136+
Tuple.class
137+
).getSingleResult();
138+
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
139+
} );
140+
// implicit join distinct + aggregate
141+
scope.inTransaction( session -> {
142+
final Tuple result = session.createQuery(
143+
"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",
144+
Tuple.class
145+
).getSingleResult();
146+
assertThat( result.get( 0, Long.class ) ).isEqualTo( 1L );
147+
} );
148+
}
149+
113150
@BeforeAll
114151
public void setUp(SessionFactoryScope scope) {
115152
scope.inTransaction( session -> {

0 commit comments

Comments
 (0)