SCBCD Guide
HomeSCJP | SCWCD | SCBCD | SCEA | SCSA

--------------------------------------------------
EJB QL
--------------------------------------------------
1. domain of a query may be restricted by the navigability of the relationships of the entity
bean on which it is based. The cmr-fields of an entity bean's abstract schema type determine navigability.
Using the cmr-fields and their values, a query can select related entity bean's and use their abstract
schema types in the query. The '.' operator is the navigation operator used to navigate through
container managed relationships.

2. The data model for container-managed persistence does not support inheritance. For this reason
entity objects or value classes of different types cannot be compared. Any EJB QL queries that
contain such comparisons are invalid.

3. Another restriction regarding the use of EJB QL is that date and time values should use the standard
Java long millisecond value.

4. The following are the reserved identifiers in EJB QL: SELECT, FROM, WHERE, DISTINCT, OBJECT, NULL, TRUE, FALSE,
NOT, AND, OR, BETWEEN, LIKE, IN, AS, UNKNOWN (not used as yet but reserved), EMPTY, MEMBER, OF and IS.

5. IS NULL is used to test whether a cmp-field or single-valued cmr-field value is NULL.
IS EMPTY tests whether or not the collection designated by the collection-valued path expression
is empty (i.e., has no elements).
(A collection-valued path expression can only be used in the WHERE clause in an empty collection comparison
expression or in a collection member expression.)

6. must define names used by entity beans in query : - Abstract Persistance Schema
can be declared in a FROM clause optionally using AS or IN :- Identification Variables
constrain the query domain :- Path Expressions
way to reference arguments from finder and select methods :- Input Parameters

7. ORDER BY is NOT supported in EJB-QL

8. Functional expressions: CONCAT, SUBSTRING, LOCATE, LENGTH, ABS, SQRT

9. Conditional expressions can use:

operators (+ - * /)
comparisons (= > >= < <= <> , for strings only = and <>
NOT
BETWEEN arithmetic-expression AND arithmetic-expression
IN: value IN (value1, value2, ...)
LIKE, using wild card characters _ and %
null comparison: IS NULL
empty comparison: collection-valued-path-expr IS EMPTY
collection member expression: MEMBER OF collection-valued-path-expr
functional expressions: CONCAT, SUBSTRING, LOCATE, LENGTH, ABS, SQRT

10. A null comparison expression tests whether or not the single valued path expression is a NULL value. Path
expressions containing NULL values during evaluation return NULL values.

11. Sample Ques:-


Name Age
Joe Bloggs 35
Dave Smith 32
Steve Jones 36 X
Sid Young 27
Simon Wood 54 X

Select all Customers whose name begins with S and are older than customer Joe Bloggs

Select Object(c1) from Customer c1,Customer c2 where c1.age > c2.age and c2.name='Joe Bloggs'

12.