|
35 | 35 | } )
|
36 | 36 | @SessionFactory
|
37 | 37 | @Jira( "https://hibernate.atlassian.net/browse/HHH-17837" )
|
| 38 | +@Jira( "https://hibernate.atlassian.net/browse/HHH-18202" ) |
38 | 39 | public class ManyToManyGroupByOrderByTest {
|
39 | 40 | @Test
|
40 | 41 | public void testSelectEntity(SessionFactoryScope scope) {
|
@@ -110,6 +111,42 @@ public void testSelectAssociationId(SessionFactoryScope scope) {
|
110 | 111 | } );
|
111 | 112 | }
|
112 | 113 |
|
| 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 | + |
113 | 150 | @BeforeAll
|
114 | 151 | public void setUp(SessionFactoryScope scope) {
|
115 | 152 | scope.inTransaction( session -> {
|
|
0 commit comments