JPA ORDER BY ClauseThe ORDER BY clause is used to sort the data and arrange them either in ascending or descending order. The CriteriaQuery interface provides orderBy() method to define the type of ordering. ORDER BY ExampleHere, we will perform several ORDER BY operations on student table. Let us assume the table contains the following records: - ![]() Now, follow the below steps to perform operations: -
StudentEntity.java
Persistence.xml
Sorting in ascending order Asc.java output: ![]() Sorting in descending order Desc.java output: ![]()
Next TopicJPA Criteria WHERE Clause
|