The Java EE 6 Tutorial

Single-Valued Query Results

The TypedQuery<T>.getSingleResult method is used for executing queries that return a single result:

CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
...
TypedQuery<Pet> q = em.createQuery(cq);
Pet result = q.getSingleResult();