I currently have a system in place which can filter and sort records in the database and return them as a Paged object. One of the lines is like this:
final
I think you could try the Spring Data JpaSort
class which allows function calls.
As stated in the documentation you will have something like :
@Query("select u from User u where u.lastname like ?1%")
List findByAndSort(String lastname, Sort sort);
repo.findByAndSort("targaryen", JpaSort.unsafe("LENGTH(firstname)"));
You could also use it with a Pageable object.