• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

HFEJB P406 - Why EJBQL SELECT Cant Return Single Valued CMR field?

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HFEJB P406, in the box it says: You can't use dot notation to return a CMR field e.g.

SELECT m.director FROM...

is invalid if 'director' is CMR field.

But, I went thru Richard Monson-Haefel's EJB book P237 where there is an example like this:

SELECT c.creditCard.creditCompany.address FROM Customer As c

'creditCard', 'creditCompany' and 'address' are all related CMR fields.

And the book says we can put CMR field in SELECT clause if it returns a single type.

So who is correct?
 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to pay real close attention to CMR versus CMP. Sometimes you'll have fields in an entity bean that have abstract getters and setters. Sometimes you'll have references to other entity beans. It's confusing. If this other book has completed code, look in the 'afterCompletion' method. Anything in there needs to have "Object(c)" kinda thing in the EJB-QL.

--Dale--
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, simply put, is this line of EJBQL legal:

SELECT m.director FROM movie m

where 'director' is a CMR field returning just a single DirectorBean.

My interpretation is HFEJB says it is not and Richard Monson-Haefel says it is. Which one should it be?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the section 11.2.8 (SELECT clause) of the EJB spec, it says that the select clause looks like this:
select_clause ::= SELECT [DISTINCT ] { single_valued_path_expression |OBJECT (identification_variable)}

Furthermore, section 11.2.6.6 (Path Expressions) mentions that single_valued_path_expression have the following form:

single_valued_path_expression ::=
{single_valued_navigation | identification_variable}.cmp_field | single_valued_navigation
single_valued_navigation ::=
identification_variable.[single_valued_cmr_field.]* single_valued_cmr_field
collection_valued_path_expression ::=
identification_variable.[single_valued_cmr_field.]*collection_valued_cmr_field

This all means that you are allowed to have CMR fields in the SELECT clause as long as it is NOT a collection valued CMR field, that is a CMR field that returns any type of Collection.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx Valentin,

Then what is HFEJB P406 talking about? In the box it says: You can't use dot notation to return a CMR field e.g.

SELECT m.director FROM...

is invalid if 'director' is CMR field.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess would be that if director is a single valued CMR field the expression is correct, and thus, RMH> is correct and HFEJB is wrong...

Anyone has another opinion?
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would be good to know Kathy's view on this subject.

Since she seems to be around these days, I bring this topic back to life ...

Section 11.4 of the spec also says this is valid in the SELECT statement, as Valentin pointed out:

identification_variable.[single_valued_cmr_field.]* single_valued_cmr_field



Can we safely say it's an error in HFEJB P406 when it's said "You can't use dot notation to return a CMR field"?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't it be

SELECT OBJECT( m.director) FROM movie m...

?
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think,

You can't use dot notation to return a CMR field



This is still true for Finder method.

SELECT OBJECT( m.director) FROM movie m



This can be used for select method only.
 
reply
    Bookmark Topic Watch Topic
  • New Topic