Java Reference
In-Depth Information
Listing 11.4. Meta-model class produced by the meta-model annotation processor
The class in this listing has static properties that you'll use to provide static typing when
building a query. The criteria query API makes extensive use of generics that when com-
bined with the static class ensure that your queries are correct and will execute. Now it's
time to start digging into the
CriteriaBuilder
.
11.2.2. CriteriaBuilder
The
CriteriaBuilder
is at the heart of the JPA criteria API. It's responsible for cre-
ating criteria queries, component selections, expressions, predicates, and orderings. It's the
factory class that you'll use to construct your query leveraging the static meta-model. You
acquire a reference to the
CriteriaBuilder
by calling the
getCriteriaBuild-
ferent types of queries that can be created using the
CriteriaBuilder
.
Table 11.10. Create methods on
CriteriaBuilder
Create method
Description
createQuery()
Creates a new criteria object
createQuery(java.lang.Class<T> resultClass)
Creates a new criteria object with a specific return type
Creates a new criteria object that will return a tuple as its
result
createTupleQuery()
Creates a new criteria object for performing bulk delete op-
erations
createCriteriaDelete( Class<T> targetEntity)