Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

HFEJB p.415: Comma in EJB-QL expression

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Wow Peer,

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

    Regards,
    Darya
     
    Consider Paul's rocket mass heater.
      Bookmark Topic Watch Topic
    • New Topic