Skip to content

Instantly share code, notes, and snippets.

@ThangLeQuoc
Created April 16, 2018 12:42
Show Gist options
  • Save ThangLeQuoc/e22f9dd02ac576ec7ca244b8d80a2de6 to your computer and use it in GitHub Desktop.
Save ThangLeQuoc/e22f9dd02ac576ec7ca244b8d80a2de6 to your computer and use it in GitHub Desktop.
Count number of result from result list
{
CriteriaBuilder qb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = qb.createQuery(Long.class);
cq.select(qb.count(cq.from(MyEntity.class)));
cq.where(/*your stuff*/);
return entityManager.createQuery(cq).getSingleResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment