background image

ExampleQueries

<< Simplified Query Language Syntax | Queries That Navigate to Related Entities >>
<< Simplified Query Language Syntax | Queries That Navigate to Related Entities >>

ExampleQueries

update_statement :: = update_clause [where_clause] delete_statement :: =
delete_clause [where_clause]
The update and delete clauses determine the type of the entities to be updated or deleted. The
WHERE
clause may be used to restrict the scope of the update or delete operation.
Example Queries
The following queries are from the Player entity of the roster application, which is
documented in
Chapter 26, "Persistence in the EJB Tier."
Simple Queries
If you are unfamiliar with the query language, these simple queries are a good place to start.
A Basic Select Query
SELECT p
FROM Player p
Data retrieved
: All players.
Description
: The FROM clause declares an identification variable named p, omitting the optional
keyword AS. If the AS keyword were included, the clause would be written as follows:
FROM Player AS
p
The Player element is the abstract schema name of the Player entity.
See also
:
"Identification Variables" on page 747
Eliminating Duplicate Values
SELECT DISTINCT
p
FROM Player p
WHERE p.position = ?1
Data retrieved
: The players with the position specified by the query's parameter.
Description
: The DISTINCT keyword eliminates duplicate values.
The WHERE clause restricts the players retrieved by checking their position, a persistent field of
the Player entity. The ?1 element denotes the input parameter of the query.
Example Queries
Chapter 27 · The Java Persistence Query Language
735