If you consult
EJB QL BNF on page 239 of the
EJB 2.0 specification you will find
from_clause ::= FROM identification_variable_declaration [, identification_variable_declaration]* identification_variable_declaration ::= collection_member_declaration | range_variable_declaration collection_member_declaration ::= IN (collection_valued_path_expression) [AS] identifier range_variable_declaration ::= abstract_schema_name [AS] identifier So
IN (d.movies) m is a
collection member declaration and
DirectorSchema d is a
range variable declaration which both can act as an
identification variable declaration - which in the FROM clause are separated by commas.
In this case its confusing because it almost looks like an "english sentence".
However
DirectorSchema d defines the Set
D of all known directors.
d.movies simply defines a collection of movies for any particular director - what we need is the Set
M of movies by
all directors which is described through
IN (d.movies) m.
So in effect the FROM clause is saying
FROM Set D, Set M.
(I chose capital D and M here because the d and m are used in the WHERE clause to refer to any single element from those Sets).
Conceptually the IN operator builds this Set by dumping all the movies reachable for all directors into one big Set. (See page 225; 11.2.6.4 Collection member declarations).
Mapping the example in the spec on page 224:
In the FROM clause declaration IN(d.movies) m, the identification variable m evaluates to any Movie value directly reachable from Director. The cmr-field movies is a collection of instances of the abstract schema type Movie and the identification variable m refers to an element of this collection. The type of m is the abstract schema type of Movie.
Hope this helps somehow.
I've used SQL for years but even after reading the Exam Study Kit
and HFEJB I still had to read the entire chapter 11 in the specification to be less confused.
In SQL, relations are either directly identified in JOINs or the WHERE clause (even though the foreign key relationship may already be defined in the RDBMS) - so this extra syntactic sugar to make use of pre-existing relationships was a bit jarring.
I'd imagine that query neophytes would be even more disturbed by the shift from the Object-Oriented to the Set paradigm.
[ October 19, 2005: Message edited by: Peer Reynders ]