JPA Criteria and JPQL

JPA

JPA2 introduced its “Criteria” queries, providing an API for typesafe query generation without the need to hardcode field names etc in queries; it built on the approach of Hibernate Criteria.
In these examples we have two classes, Inventory and Product, where Inventory has a set of products.

Select of persistable objects with simple filter

JPQL single-string would be

JPA Criteria would be

JPQL single-string would be

JPA Criteria would be

Select of aggregate of attribute of persistable objects

JPQL single-string would be

JPA Criteria would be

Select of persistable objects with simple filter and parameter

JPQL single-string would be

JPA Criteria would be

Select of persistable objects with joined filter condition

JPQL single-string would be

JPA Criteria would be

Select of persistable objects with subquery filter

JPQL single-string would be

JPA Criteria would be

If you think something is wrong please feel free to comment :)