How do I add Restrictions to the Criteria object?
Category: org.hibernate, viewed: 3878 time(s).
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 Restrictions.eq(), Restrictions.like() and Restrictions.isNotNull().
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 add() method.
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 propertyRestrictions.or(criterionA, criterionB)- Return the disjuction of two expressions.Restrictions.disjuction()- Group expressions together in a single disjunction.
Download Hundreds of Complimentary Industry Resources
Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more;
all available at no cost to you. With more than 600 complimentary offers, you'll find
plenty of titles to suit your professional interests and needs.
Click Here and Sign up today!


