• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • 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?
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • 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
  • 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
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • 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?
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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"?
 
Kirk Woerner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't it be

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

?
 
Vaithiya Sundaram
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic