10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example Queries<br />

update_statement :: = update_clause [where_clause] delete_statement :: =<br />

delete_clause [where_clause]<br />

<strong>The</strong> update and delete clauses determine the type of the entities to be updated or deleted. <strong>The</strong><br />

WHERE clause may be used to restrict the scope of the update or delete operation.<br />

<strong>The</strong> following queries are from the Player entity of the roster application, which is<br />

documented in Chapter 26, “Persistence in the EJB Tier.”<br />

Simple Queries<br />

If you are unfamiliar with the query language, these simple queries are a good place to start.<br />

A Basic Select Query<br />

SELECT p<br />

FROM Player p<br />

Data retrieved: All players.<br />

Description: <strong>The</strong> FROM clause declares an identification variable named p, omitting the optional<br />

keyword AS.IftheAS keyword were included, the clause would be written as follows:<br />

FROM Player AS<br />

p<br />

<strong>The</strong> Player element is the abstract schema name of the Player entity.<br />

See also: “Identification Variables” on page 745<br />

Eliminating DuplicateValues<br />

SELECT DISTINCT<br />

p<br />

FROM Player p<br />

WHERE p.position = ?1<br />

Data retrieved: <strong>The</strong> players with the position specified by the query’s parameter.<br />

Description: <strong>The</strong> DISTINCT keyword eliminates duplicate values.<br />

Example Queries<br />

<strong>The</strong> WHERE clause restricts the players retrieved by checking their position, a persistent field of<br />

the Player entity. <strong>The</strong> ?1 element denotes the input parameter of the query.<br />

Chapter 27 • <strong>The</strong> <strong>Java</strong> Persistence Query Language 733

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!