title: Sorting a custom JPA query with pageable
body: <p>So, I've already done this using the standard Spring Data JPA interface which extends PagingAndSortingRepository in order to achieve pagination and sorting for a REST API. The thing is, now I want to achieve the very same thing but now using just vanilla JPA and so far so good I managed to get my API to paginate but the sorting doesn't work at all. Every time I try to set the parameter (from a pageable object using pageable.getSort()) it ends with a query error (either if I just send a string as parameter like "name" or just send the sort object, it shows errors).</p>
  
  <p>Here's some code:</p>
  
  <p>My repo implementation:</p>
  
  <pre><code>    @Override
  public List&lt;Project&gt; findByAll(Pageable pageable) {
      Query query = em.createQuery("SELECT project FROM Project project ORDER BY :sort");
      query.setParameter("sort", pageable.getSort());
      query.setMaxResults(pageable.getPageSize());
      query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber());
      return query.getResultList();
  }
  </code></pre>
  
  <p>My service:</p>
  
  <pre><code>@Override
  public Page&lt;Project&gt; findAll(Pageable pageable) {
      objects = Lists.newArrayList(repository.findByAll(pageable));
      PageImpl&lt;Project&gt; pages= new PageImpl&lt;Project&gt;(objects, pageable, repository.count());
      return pages;
  }
  </code></pre>
  
  <p>To be clear, I'm filling the Pageable object via URI and from the console I can say it's actually getting the data, so I assume the problem is with the repo.</p>
  
  <p>Edit: This is the error I get when I replace the setParameter("sort", ...) for a hardcoded string aka query.setParameter("sort", "name"):</p>
  
  <pre><code>java.lang.NumberFormatException: For input string: "name"
  </code></pre>
  
  <p>And I think this method should stand for strings as well. If I use query.setParameter("sort", pageable.getSort()), the error is the same.</p>