2. Executing a CriteriaQuery

A CriteriaQuery is executed in a similar fashion to 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.

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