0

I'm using spring boot 2.1.9 Ihave some repositories extended QuerydslPredicateExecutor and I need to sort enteties by specific value, plain sql works fine

select * from attachment_points order by kpp =1 desc;

I have about 50 entitis to add sorting, is there a way to add sorting to existing method

Page<T> findAll(Predicate predicate, Pageable pageable);

I've tried to add sort to pagable

JpaSort.unsafe(Sort.Direction.DESC, "kpp=1")

but I've dot error

threw exception [Request processing failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property kpp=77 found for type AttachmentPoint!] with root cause
Anna
  • 1
  • What database are you using? kpp = 1 in the sort is not supported by JPA and also not by all databases. – Simon Martinelli Nov 11 '21 at 16:57
  • I'm using Postgres. Found the solution: query DSL Qsort with OrderSpecifiers thanks to https://stackoverflow.com/questions/51023675/querydsl-conditional-order-by https://stackoverflow.com/questions/11673213/how-to-do-a-paged-querydsl-query-with-spring-jpa – Anna Nov 13 '21 at 09:06

0 Answers0