-
Notifications
You must be signed in to change notification settings - Fork 16
Semantic Criteria API
Martin Ledvinka edited this page May 27, 2024
·
3 revisions
The Semantic Criteria API is a programmatic query API based on JPA's Criteria API. It internally translates to SOQL, so its functionality is currently slightly limited.
Nevertheless, it allows one to dynamically create type-safe queries, utilizing the entity metamodel created by JOPA.
EntityManager em = // get an EntityManager instance
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> query = cb.createQuery(Integer.class);
Root<Concept> root = query.from(Concept.class);
query.select(cb.count(root));
final Integer result = getEntityManager().createQuery(query).getSingleResult();
This example gets the count of instances of class Concept
.
More examples can be found in the CriteriaRunner
in the jopa-integration-tests module.