background image

Bulk Updates and Deletes

<< The IS EMPTY Expression | BNF Grammar of the Java Persistence Query >>
<< The IS EMPTY Expression | BNF Grammar of the Java Persistence Query >>

Bulk Updates and Deletes

Bulk Updates and Deletes
The following examples show how to use the UPDATE and DELETE expressions in queries. UPDATE
and DELETE operate on multiple entities according to the condition or conditions set in the
WHERE
clause. The WHERE clause in UPDATE and DELETE queries follows the same rules as SELECT
queries.
Update Queries
UPDATE Player p
SET p.status =
'inactive'
WHERE p.lastPlayed < :inactiveThresholdDate
Description
: This query sets the status of a set of players to inactive if the player's last game
was longer than the date specified in inactiveThresholdDate.
Delete Queries
DELETE
FROM Player p
WHERE p.status =
'inactive'
AND p.teams IS EMPTY
Description
: This query deletes all inactive players who are not on a team.
Full Query Language Syntax
This section discusses the query language syntax, as defined in the Java Persistence
specification. Much of the following material paraphrases or directly quotes the specification.
BNF Symbols
Table 27­1
describes the BNF symbols used in this chapter.
TABLE 27­1
BNF Symbol Summary
Symbol
Description
::=
The element to the left of the symbol is defined by the constructs on the right.
*
The preceding construct may occur zero or more times.
{...}
The constructs within the curly braces are grouped together.
Full Query Language Syntax
The Java EE 5 Tutorial · September 2007
740