As this code in FetchableFluentQueryBySpecification shows, adding a limit applies the current sorting again.
|
@Override |
|
public FetchableFluentQuery<R> limit(int limit) { |
|
|
|
Assert.isTrue(limit >= 0, "Limit must not be negative"); |
|
|
|
return new FetchableFluentQueryBySpecification<>(spec, entityType, resultType, this.sort.and(sort), limit, |
|
properties, finder, scroll, countOperation, existsOperation, entityManager, projectionFactory); |
|
} |
In my application, this is causing duplicate order by clause to be included in the SQL generated like order by q1_0."id" desc,q1_0."id" desc, as I call .sortBy first, and then .limit.
Of course, it's easy to fix on the application's side by calling .limit first, but I think this is a bug in the framework, as the other class FetchableFluentQueryByPredicate implementing the same interface does not have this behavior.
As this code in
FetchableFluentQueryBySpecificationshows, adding alimitapplies the current sorting again.spring-data-jpa/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryBySpecification.java
Lines 96 to 103 in b00220b
In my application, this is causing duplicate
order byclause to be included in the SQL generated likeorder by q1_0."id" desc,q1_0."id" desc, as I call.sortByfirst, and then.limit.Of course, it's easy to fix on the application's side by calling
.limitfirst, but I think this is a bug in the framework, as the other classFetchableFluentQueryByPredicateimplementing the same interface does not have this behavior.