Using the Criteria API

The Criteria API provides a way of creating type-safe queries. Its type-safe quality is the result of the Java compiler's ability to perform syntax checking at compile-time and the run-time environment's ability to catch and handle exceptions. Using this API can result in more robust and stable applications.

The Criteria API is a complex API. Complete coverage is not possible here. The intent is to provide an introduction to its use.

Getting ready

The essential steps in creating and using a Criteria API-based query are:

  1. Creating an instance of the CriteriaBuilder class
  2. Using this instance to create an instance of a CriteriaQuery class containing a query
  3. Executing the query

How to do it...

There are two basic approaches for using ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.