Java Reference
In-Depth Information
Identifier variables
In the JPQL example, you defined an identifier variable named
c
, and you used that vari-
able in other clauses, such as
SELECT
and
WHERE
. A simple identifier variable is defined
using the following general syntax:
FROM entityName [AS] identificationVariable
The square brackets (
[]
) indicate that the
AS
operator is optional. The identifier variable
(which isn't case sensitive) must be a valid Java identifier, and it must not be a JPQL re-
served identifier.
Table 11.2
lists all of the JPQL reserved identifiers for your convenience.
Keep in mind that the identifier can't be the name of another entity packaged in the same
persistence unit.
Table 11.2. JPQL keywords reserved by the specification. You're not allowed to give any of your variables these
names.
Types
Reserved words
SELECT, UPDATE, DELETE, FROM, WHERE, GROUP, HAVING, ORDER,
BY, ASC, DESC
Statements and clauses
Joins
JOIN, OUTER, INNER, LEFT, FETCH
DISTINCT, OBJECT, NULL, TRUE, FALSE, NOT, AND, OR, BETWEEN,
LIKE, IN, AS, UNKNOWN, EMPTY, MEMBER, OF, IS, NEW, EXISTS,
ALL, ANY, SOME
Conditions and operators
AVG, MAX, MIN, SUM, COUNT, MOD, UPPER, LOWER,
TRIM,POSITION, CHARACTER_LENGTH, CHAR_LENGTH,
BIT_LENGTH, CURRENT_TIME, CURRENT_DATE,
CURRENT_TIMESTAMP
Functions
Thus, you can't define the
FROM
clause like this
FROM Category User
or like this
FROM Category Max
because you already have an entity named
User
in the ActionBazaar application, and
MAX
is a reserved identifier.