How to add Restrictions to the Criteria object?
In this example you'll learn how to add restrictions to the
Criteria object. Using restriction we can narrow the result of our query. In the code below we add some restrictions such as
In the Hibernate framework you'll find a lot of class the use a method chaining. As in the example below you can see that we actually can add an endless restrictions by calling the
Here are some other restrictions that can also be use to narrow our
Criteria query result, for a complete restrictions you can see the Restrictions class documentation.
Restrictions.ne("title", "Twist and Shout") - Apply a "not equal" constraint to the named property.
Restrictions.ilike("title", "Twist%") - A case-insensitive "like".
Restrictions.isNull("title") - Apply an "is null" constraint to the named property.
Restrictions.gt("duration", new Integer(200)) - Apply a "greater than" constraint to the named property.
Restrictions.between("duration", new Integer(100), new Integer(200)) - Apply a "between" constraint to the named property
Restrictions.or(criterionA, criterionB) - Return the disjuction of two expressions.
Restrictions.disjuction() - Group expressions together in a single disjunction.