In the last tutorial, we have introduced how to use HQL for querying persistent objects. Hibernate is providing an alternative method called “Criteria Queries” for this task. | Hibernate Tutorial 10 Criteria Queries By Gary Mak hibernatetutorials@ September 2006 1. Using criteria queries In the last tutorial we have introduced how to use HQL for querying persistent objects. Hibernate is providing an alternative method called Criteria Queries for this task. It is a set of API for us to build up a query in a more programmatic way comparing to HQL. Sometimes we need to build up a query dynamically in our application . for an advanced search function. The traditional method of doing this is to generate a HQL statement or SQL statement if not using Hibernate by string concatenation. The problem for this method is making your code hard to maintain because of the hard reading statement fragments. Criteria criteria name Hibernate Quickly List books This criteria query corresponds to the following HQL query. from Book book where Hibernate Quickly Most methods in the Criteria class return the instance of itself so that we can build up our criteria in the following way. Criteria criteria .add name Hibernate Quickly List books 2. Restrictions We can add a series of restrictions to our criteria query to filter the results just like building up the where clause in HQL. The Restrictions class provides a variety of methods for restriction building. Each restriction added will be treated as a logical conjunction. Criteria criteria .add name Hibernate .add price new Integer 100 new Integer 200 List books Page 1 of 4 So this criteria query corresponds to the following HQL query. from Book book where like Hibernate and between 100 and 200 We can also group some of the restrictions with logical disjunction. Criteria criteria .add .