The SELECT clause in EJB-QL determines what is returned by the query. As per the rules of EJB QL, the SELECT clauses are classified into 2 types.
1. SELECT clauses with RANGE variables
2. SELECT clauses with single-valued path expressions
When you want to return a collection of component interfaces, you have to use 1. Whenever you use option 1, you must use OBJECT in your SELECT clause.
Example : SELECT OBJECT (l) FROM ORDER o, IN (o.lineitems) l
This returns a collection of line item component interface references belonging to all the Orders in the database.
When you do not want to return a collection of component interface references, but you want to return a collection of a CMP field type, you have to use option 2.
Ex : SELECT l.product FROM ORDER o, IN(o.lineitems) l
is valid assuming product is a CMP field. This takes all the Orders in the database that have atleast one line item and returns each of the line item's product. Hence it returns a collection of products.
Important rule : You cannot have a CMR field as the SELECT return type This rule is violated by 2 and hence is invalid.
If you want to return a collection of a CMR field type,
you should not use the option 2 (single-valued path expression) as it would violate the above rule. Your only option is option 1 (Range variable), hence 3 is valid