Java Reference
In-Depth Information
Table 11.1. Statement types supported by JPQL
Statement type
Description
Select
Retrieves entities or entity-related data
Update
Updates one or more entities
Delete
Deletes one or more entities
Let's first focus on retrieving entities using a SELECT statement with JPQL.
Defining and using SELECT
Let's get jump-started with a simple JPQL query:
SELECT c
FROM Category c
WHERE c.categoryName LIKE :categoryName
ORDER BY c.categoryId
This JPQL query has (or can have) the following:
• A required SELECT clause specifying the object type, entity, or values being re-
trieved
• A required FROM clause specifying an entity declaration that's used by other
clauses
• An optional WHERE clause to filter the results returned by the query
• An optional ORDER BY clause to order the results retrieved by the query
• An optional GROUP BY clause to perform aggregation
• An optional HAVING clause to perform filtering in conjunction with aggregation
Defining UPDATE and DELETE
In the last chapter we discussed updating and removing entities using the EntityMan-
ager API. But these were limited to only one entity instance. What about when you want
to remove more than one entity in a single call? Like SQL, JPQL also provides UPDATE
and DELETE statements to perform updates and deletions of entities, and you can continue
to specify a condition using a WHERE clause. These statements are quite similar to their
SQL relatives. They're referred to as bulk updates or deletes, because you'll primarily use
these to update or delete a set of entities matching a specific condition. In this section we'll
limit our discussion to the JPQL syntax for update and delete statement types.
 
Search WWH ::




Custom Search