Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<User> criteriaQuery = criteriaBuilder.createQuery(User.class);
Root<User> userRoot = criteriaQuery.from(User.class);
//Specification<User> specs = (root, query, cb) ->
// cb.equal(root.get("createdAt"), utcDate);
String paramName = "pn";
Specification<User> specs = (root, query, cb) ->
cb.equal(root.get("createdAt"), cb.parameter(Date.class, paramName));
Predicate predicate = specs.toPredicate(userRoot, criteriaQuery, criteriaBuilder);
//TypedQuery<User> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.setParameter(paramName, utcDate);
List<User> results = typedQuery.getResultList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment