O'Reilly logo

Spring Data by Petri Kainulainen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sorting query results

In the course of this section, we will learn different techniques that can be used to sort query results with Spring Data JPA. We will also learn the guidelines that we can use to select a proper sorting method for each situation.

Sorting with method name

If we are building our queries by using the query generation from the method name strategy, we can sort query results by the following steps:

  1. Creating a query method
  2. Modifying an existing service method to use the new query method.

Creating the query method

When we are building our queries by using the query generation from the method name strategy, we can use the OrderBy keyword to sort the query results when we:

  1. Append the OrderBy keyword to the method name.
  2. Append the property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required