Tuesday, August 28, 2007

Hibernate Criteria Interface

clipped from www.hibernate.org



org.hibernate

Interface Criteria


Criteria is a simplified API for retrieving entities
by composing Criterion objects. This is a very
convenient approach for functionality like "search" screens
where there is a variable number of conditions to be placed
upon the result set.

The Session is a factory for Criteria.
Criterion instances are usually obtained via
the factory methods on Restrictions. eg.

 List cats = session.createCriteria(Cat.class)
.add( Restrictions.like("name", "Iz%") )
.add( Restrictions.gt( "weight", new Float(minWeight) ) )
.addOrder( Order.asc("age") )
.list();
 List cats = session.createCriteria(Cat.class)
.createCriteria("kittens")
.add( Restrictions.like("name", "Iz%") )
.list();
 List cats = session.createCriteria(Cat.class)
.createAlias("kittens", "kit")
.add( Restrictions.like("kit.name", "Iz%") )
.list();

0 comments: