2. Executing a CriteriaQuery

A CriteriaQuery is executed in a similar fashion of a string-based JPQL query via the EntityManager and Query interfaces.

EntityManager em = ...
Query query = em.createQuery(qdef);
List result = query.getResultList();    

A query definition can use named parameters, and the parameter values are set as usual in the Query instance.

The JPA 2.0 Specification on Criteria API can be found at public draft.

A developerworks article explains details and further usage of Criteria API and its OpenJPA extensions.