Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Spring Data

You're reading from  Spring Data

Product type Book
Published in Nov 2012
Publisher Packt
ISBN-13 9781849519045
Pages 160 pages
Edition 1st Edition
Languages
Author (1):
Petri Kainulainen Petri Kainulainen
Profile icon Petri Kainulainen
Toc

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 expression that corresponds to the property of the entity, which is used to sort the query results, to the method name.

  3. Append a keyword describing the sorting order to the method name. If the query results are sorted in ascending order, the keyword...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime}