4

I got to grips with using Spring Data JPA however I stumbled upon an issue, searched all the net but still didn't find an answer. I got the repository working and even the paging and sorting. However, it seems that when I do the same, but specifying a named query in the @Query annotation, rather than letting Spring generate the query at runtime, the sortable part of the Pageable object is completely ignored. I can confirm this as the query generated by Hibernate does not have an "ORDER BY" clause in the latter case.

public interface TransactionRepository extends JpaRepository<Transaction, Long>
{           
    @Query(name = "Transaction.findParentTransactionsByStatus", countName = "Transaction.findCountParentTransactionsByStatus")
    public Page<Transaction> findParentTransactionsByStatus(@Param(value = "status") TransactionStatus status, Pageable pageable);

Any ideas?

1 Answers1

3

Can you post the actual HQL from your named query Transaction.findParentTransactionsByStatus?

The reason I am asking is, I encountered this same issue and it was because I had an extra end parenthesis ")" in my HQL. For some reason, it was being accepted as a valid HQL, but when passing the sort via Pageable, it was not including the sort column. My solution was to remove that extra parenthesis and it worked

Carlos Jaime C. De Leon
  • 2,476
  • 2
  • 37
  • 53