HQL (Hibernate Query Language) - Hibernate Query Language is similar to Structured Query Language).But only difference is it does not depend on table of the database. It depends on class name in HQL, so it is database independent query.
Advantage of HQL:
- Database independent.
- Supports polymorphic queries.
- Easy to learn for Java Programmer.
Example of HQL :
To get all the records:
To get records with pagination:
Update query :
Delete query :
Aggregate functions: aggregate functions by HQL. example avg(), min(), max() etc.
Some common examples:
To get total salary of all the employees :
To get maximum salary of employee :
To get minimum salary of employee:
To count total number of employee ID :
To get average salary of each employees: