-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Milan Milanov opened DATAJPA-1643 and commented
I'm using the spring boot starter JPA version 2.2.1 RELEASE, which pulls the spring data JPA project with the same dependency. I'd like to use the specification + paging findAll method, but with a twist, that the sorting should be done based on a function, and not on a simple property.
Sort sort = JpaSort.unsafe("nlssort(entity_title, 'NLS_SORT = XGERMAN_DIN_AI')");
var activities = entityRepository.findAll(new EntitySpecification(...), PageRequest.of(0, 10, sort))
Running this code I get an exception saying that No property nlssort(entity found for type Entity!
. The same question is asked here, and in fact the accepted answer actually works. The problem is that adding a query doesn't play along with a specification. Just for test i tried:
@Query("SELECT s FROM Entity s")
Page<Entity> findAll(Specification<Entity> spec, Pageable pageable);
Then the query is actually generated and executed, but all results are just sorted, nothing is filtered. Also i don't know how this would work since there are aliases, but nevertheless:
SELECT *
FROM (SELECT ...
entity0_.entity_title AS entity_title6_1_,
...
FROM entities entity0_
ORDER BY nlssort(entity_title, 'NLS_SORT = XGERMAN_DIN_AI') ASC)
WHERE ROWNUM <= ?
Affects: 2.2.3 (Moore SR3)