HCQL (Hibernate Criteria Query Language) : The Hibernate Criteria Query Language (HCQL) is used to fetch the data based on specific criteria/condition. The Criteria interface provides the methods to get data according to condition. Ex: From a table whose salary is greater than 10000.
Advantage of HCQL : The HCQL provides methods to add criteria. Through this we can add some criteria according to need.
Syntax of createCriteria() method of Session interface :
Examples of Hibernate Criteria Query Language :
To get all the records:
To get the 20th to 30th record:
To get the records whose salary is greater than 50000 :
To get the records in ascending order on the basis of salary:
HCQL with Projection : If we want particular field such as name than we use projection