EJB 3 provides the Java Persistence Query Language (JPQL). In this chapter we will cover:
Projections
GROUP BY and HAVING clauses
Joins
Subqueries
Dynamic Queries
Functions
Queries with parameters
Handling Date and Time
Bulk update and delete operations
Native SQL
A rather limited query language, EJB QL, was provided in EJB 2.0 and 2.1. JPQL enhances EJB QL by providing the following features: JOINs, GROUP BY, HAVING, projection, subqueries, dynamic queries, bulk update and delete. We shall see examples of all these features in this chapter.
JPQL is similar to the SQL language for querying relational databases. However, JPQL queries are expressed in Java objects rather than tables and columns. As SQL dialects differ between relational database vendors, JPQL has an added advantage of portability across databases. The entity manager uses the JDBC configuration specified in the persistence.xml
file to convert the JPQL query to native SQL.
There...