wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes HFEJB p.415: Comma in EJB-QL expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "HFEJB p.415: Comma in EJB-QL expression" Watch "HFEJB p.415: Comma in EJB-QL expression" New topic
Author

HFEJB p.415: Comma in EJB-QL expression

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

please view the comma (,) in the following EJB-QL expression with IN operator from HFEJB p.415:



I wonder whether the comma is a typo or is rightful . I can think of that the comma is correct due to the fact that we have two declarations (d AND m) in the 2nd line (FROM DirectorSchema d, IN (d.movies) m)

Do you agree?

Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
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 ]
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Wow Peer,

    this is an incredible (wonderful ) response. Thanks a lot for this one.

    Regards,
    Darya
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: HFEJB p.415: Comma in EJB-QL expression
     
    Similar Threads
    Is this query okay?
    Why DISTINCT with OBJECT in QL?
    regarding EJB QL
    PMR question on HF EJB book
    EJB-QL question