The really great thing about the Hibernate Criteria API is that it allows developers to really look at their problems in an object oriented way. You think about what you need from your object model, not how to do a query to get what you want. This is great, as Java developers are notoriously bad at SQL and HQL.
So, for example, to find all users who have verified their password, you can use the Critieria API's Example object, and just execute code such as this:
Code:
User user = new User();
user.setVerified(false);
Example example = Example.create(user);
Session session = HibernateUtil.beginTransaction();
Criteria criteria = session.createCriteria(User.class);
criteria.add(example);
List results = criteria.list();
HibernateUtil.commitTransaction();
for (int i = 0; i<results.size(); i++) {
System.out.println(results.get(i).toString());
}
As you can see, there is no HQL or SQL - just Java objects with various properties populated. It really is awesome.
I took this example from a little tutorial on the Hibernate3 Criteria API. If you'd like to take a look at those Hibernate examples, they're right here:
http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=09howtousethecriteriaapi