Hello,
I have a query derivation method with the name:
public Page<Admin> findByFirstnameStartingWithOrLastnameStartingWithO rderByLastnameAscFirstnameAsc(String searchTerm, Pageable page);
The name contains a sorting clause with its: OrderByLastnameAscFirstnameAsc(
What happens if I use it like this ?
In the same fashion, if the query is done with a @Query annotation, do we have an issue as well ?
Kind Regards,
I have a query derivation method with the name:
public Page<Admin> findByFirstnameStartingWithOrLastnameStartingWithO rderByLastnameAscFirstnameAsc(String searchTerm, Pageable page);
The name contains a sorting clause with its: OrderByLastnameAscFirstnameAsc(
What happens if I use it like this ?
Code:
// Should a Sort order be passed in the page request ? What of the sort order in the method name ?
Pageable pageRequest = buildPageRequest(0, 10);
Page<Admin> admins = adminRepository.findByFirstnameStartingWithOrLastnameStartingWithOrderByLastnameAscFirstnameAsc("zfirstname", pageRequest);
private Pageable buildPageRequest(int pageIndex, int pageSize) {
Sort sort = new Sort(new Sort.Order(Sort.Direction.ASC, "lastname"), new Sort.Order(Sort.Direction.ASC, "firstname"));
return new PageRequest(pageIndex, pageSize, sort);
}
Code:
@Query("SELECT a FROM Admin a WHERE LOWER(a.firstname) LIKE LOWER(CONCAT('%', :searchTerm)) OR LOWER(a.lastname) LIKE LOWER(CONCAT('%', :searchTerm)) ORDER BY a.lastname ASC, a.firstname ASC")
public Page<Admin> findByFirstnameStartingWithOrLastnameStartingWith(@Param("searchTerm") String searchTerm, Pageable page);