Chapter 15. The query languages

 

In this chapter

  • Writing JPQL and criteria queries
  • Retrieving data efficiently with joins
  • Reporting queries and subselects

Queries are the most interesting part of writing good data access code. A complex query may require a long time to get right, and its impact on the performance of the application can be tremendous. On the other hand, writing queries becomes much easier with more experience, and what seemed difficult at first is only a matter of knowing the available query languages.

This chapter covers the query languages available in JPA: JPQL and the criteria query API. We always show the same query example with both languages/API, where the result of the queries is equivalent.

15.1. Selection

15.1.1. Assigning aliases and query roots

15.1.2. Polymorphic queries

15.2. Restriction

15.2.1. Comparison expressions

15.2.2. Expressions with collections

15.2.3. Calling functions

15.2.4. Ordering query results

15.3. Projection

15.3.1. Projection of entities and scalar values

15.3.2. Using dynamic instantiation