CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery
criteriaQuery = criteriaBuilder.createQuery(Employee.class);
Root
employee = criteriaQuery.from(Employee.class);
Predicate condition = criteriaBuilder.gt(employee.get(Employee_.age), 24);
criteriaQuery.where(condition);
TypedQuery
typedQuery = em.createQuery(criteriaQuery);
List
result = typedQuery.getResultList();
比如: CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery
criteriaQuery = criteriaBuilder.createQuery(Employee.class);
Employee实体的查询根对象可以用以下的语法获得 :
Root
employee = criteriaQuery.from(Employee.class);