Skip to content

Commit 8b4c46e

Browse files
committed
CAY-2836 ObjectSelect.selectCount() throws if a query contains ordering
1 parent cd58cdd commit 8b4c46e

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CAY-2897 Add no-op default implementations to the GraphChangeHandler interface
1919

2020
Bug Fixes:
2121

22+
CAY-2836 ObjectSelect.selectCount() throws if a query contains ordering
2223
CAY-2883 License and notice templates are not processed by the Gradle build
2324
CAY-2885 Modeler: DbImport fails to load DB schema view
2425
CAY-2887 Expressions: Incorrect serialization to string of numeric literals

cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,10 @@ public ObjectSelect<T> distinct() {
678678
* @return count of rows
679679
*/
680680
public long selectCount(ObjectContext context) {
681-
return count().selectOne(context);
681+
ColumnSelect<Long> count = count();
682+
// reset orderings, see CAY-2836
683+
count.orderings = Collections.emptyList();
684+
return count.selectOne(context);
682685
}
683686

684687
@Override

cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelect_RunIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,12 @@ public void test_CAY_2092() {
236236
assertNotNull(artist);
237237
}
238238
}
239+
240+
@Test
241+
public void test_CAY_2836_countWithOrdering() {
242+
long count = ObjectSelect.query(Artist.class)
243+
.orderBy(Artist.ARTIST_NAME.asc())
244+
.selectCount(context);
245+
assertEquals(20, count);
246+
}
239247
}

0 commit comments

Comments
 (0)