Executing String-Based Queries - The Java EE 6 Tutorial (original) (raw)
String-based queries are executed similarly to strongly-typed Criteria queries. First create a javax.persistence.TypedQueryobject by passing the criteria query object to the EntityManager.createQuery method and then call either getSingleResult or getResultList on the query object to execute the query.
CriteriaQuery cq = cb.createQuery(Pet.class); Root pet = cq.from(Pet.class); cq.where(cb.equal(pet.get("name"), "Fido")); TypedQuery q = em.createQuery(cq); List results = q.getResultList();
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices