spring-projects / spring-projects/spring-data-relational

Custom query with sort parameter [DATAJDBC-589]

Open
#811 11 comments 5 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Dec 31, 2020.

in: repository status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
827
Forks
394
PR merge metrics
No merged PRs in 30d

Description

kremerkp opened DATAJDBC-589 and commented

I try to add an dynamicly "order by" clause by passing a parameter inside a custom query. Limit and offset are working fine as parameters, only the order by is not recognized

Example:

// code public interface CustomerRepository extends PagingAndSortingRepository<Customer, Long> 

     @Query("select * from person where firstname = :name" + " order by :order")
           List<Customer> findByFirstNameCustomQuery(@Param("name") String name, 
Pageable page, @Param("order") String order);

The query that I normaly use is more complex, so that I wont be able to use query creation from method names.

Is there a workaround or will it be "fixed/added" in a future release?

I also added a small GitHub Repo do demonstrate the problem;

https://github.com/kremerkp/spring-data-jdbc-pageable-h2

 


Reference URL: https://stackoverflow.com/questions/63285038/spring-data-customized-query-with-order-parmeter-nor-working

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.