78
JPA JPQL Advanced Operations
Using JPQL, we can perform any type of database operations. Here, we will perform some advanced operations of JPQL using simple examples.
Let us consider the student table having the following records.
JPQL Advanced Query Examples
In this example, we will take a basic entity class (in this case StudentEntity.java) and perform different operations on it.
- Create an entity class named as StudentEntity.java under com.tutoraspire.jpa package.
StudentEntity.java
- Now, map the entity class and other databases confiuguration in Persistence.xml file.
Persistence.xml
- Now, we can perform any of the following operations on StudentEntity.java class.
JPQL Filter
Here, we will perform some filter operations on a table.
Filter.java
Output:
JPQL Aggregate
Here, we will perform some aggregate operations on a table.
Aggregate.java
Output:
JPQL Sorting
Here, we will sort the elements of table on the basis of s_age attribute.
Sorting.java
Output:
Next TopicJPA Criteria API