Querying with the Criteria API

    The entity provider calls specific QueryModifierDelegate methods at different stages while making a query. The stages are:

    1. Start building a query

    2. Add “ WHERE” expression (filter)

    All the methods get two parameters. The CriteriaBuilder is a builder that you can use to build queries. The CriteriaQuery is the query being built.

    You can use the getRoots().iterator().next() in CriteriaQuery to get the “root” that is queried, for example, the PERSON table, etc.

    Let us consider a case where we modify the query for a Person container so that it includes only people over 116. This trivial example is identical to the one given earlier using the Filterable interface.

    See the on-line example.

    Compatibility

    When building queries, you should consider the capabilities of the different JPA implementations. Regarding Hibernate, see “Joins in Hibernate vs EclipseLink”.