Skip to content

Commit 7802667

Browse files
committed
CAY-2836 ObjectSelect.selectCount() throws if a query contains ordering
1 parent 85dca2f commit 7802667

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
@@ -22,6 +22,7 @@ CAY-2897 Add no-op default implementations to the GraphChangeHandler interface
2222
Bug Fixes:
2323

2424
CAY-2701 MySQL DST-related LocalDateTime issues
25+
CAY-2836 ObjectSelect.selectCount() throws if a query contains ordering
2526
CAY-2871 QualifierTranslator breaks on a relationship with a compound FK
2627
CAY-2872 CayenneModeler "Documentation" link is broken
2728
CAY-2876 Memory leak in the ObjectStore

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ public ObjectSelect<T> distinct() {
328328
* @return count of rows
329329
*/
330330
public long selectCount(ObjectContext context) {
331-
return count().selectOne(context);
331+
ColumnSelect<Long> count = count();
332+
// reset orderings, see CAY-2836
333+
count.orderings = List.of();
334+
return count.selectOne(context);
332335
}
333336

334337
@Override

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,12 @@ public void test_CAY_2092() {
246246
assertNotNull(artist);
247247
}
248248
}
249+
250+
@Test
251+
public void test_CAY_2836_countWithOrdering() {
252+
long count = ObjectSelect.query(Artist.class)
253+
.orderBy(Artist.ARTIST_NAME.asc())
254+
.selectCount(context);
255+
assertEquals(20, count);
256+
}
249257
}

0 commit comments

Comments
 (0)