Hibernate - SPLessons

Hibernate HCQL

Chapter 36

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Hibernate HCQL

Hibernate HCQL

shape Description

Hibernate HCQL stands for Hibernate Criteria Query Language that utilized to select the data from the database, by using criteria query language only complete objects will be selected, but not partial objects. Using Hibernate HCQL the projection and criterion concepts it is possible to select partial objects also. The advantage of Hibernate HCQL provides more criteria’s on a query, here criteria can not perform non selection operations. Following is Hibernate HCQL the syntax to perform criteria.
Criteria crit = session.createCriteria(–Our class object–);

shape Example

Following is an example to get the all records from the database.

Crietria c=session.createCriteria(Emp.class);//passing Class class argument  
List list=c.list();  

Following is an example to get particular record for instance record 12 and 13.

Crietria c=session.createCriteria(Emp.class);  
List list=c.list();  

Following is an example to get the data where salary should me 100000.

Crietria c=session.createCriteria(Emp.class);  
c.add(Restrictions.gt("salary",100000));//salary is the propertyname  
List list=c.list();  

Following is an example to arrange the salary in ascending order.

Crietria c=session.createCriteria(Emp.class);  
List list=c.list();  

Following is an example to get partial object from the database such as address.

Criteria c=session.createCriteria(Emp.class);  
List list=c.list();  


shape Key Points

  • Hibernate HCQL – Criterion is an interface.
  • Restrictions class is used to get an criterion object.
  • org.hibernate.criterion is a package under this package criterion and restriction class available.
  • Projection is utilized to get partial objects from database.