aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Enthuware question doubt regarding JPQL 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 "Enthuware question doubt regarding JPQL" Watch "Enthuware question doubt regarding JPQL" New topic
Author

Enthuware question doubt regarding JPQL

Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Hi,

While practicing today I stumbled upon this enthuware's question:

Given that a Student may enroll in many Courses. Match the following queries with the result returned by the queries. (Assume that relationship is bidirectional).

1. SELECT s from Student s
Ans: get all students

2. SELECT c from Student s, IN(s.courses) c
Ans: get all courses having at least one enrollment

3. SELECT s form Student s where s.courses IS EMPTY
Ans: get all students who are not enrolled in any course

4. SELECT s.courses from Student s
Ans: get all courses having at least one enrollment

I agree with the answers given for the first three statements. However, I think that the 4th is not a valid JPQL statement.

According to the JPA specification, section 4.8 (SELECT clause):

Note that the SELECT clause must be specified to return only single-valued expressions. The query below is therefore invalid:
SELECT o.lineItems from Order AS o


What do other fellow ranchers think about this? Am I mistaken here?

Thank you in advance.
[ September 07, 2008: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,
you are perfectly right.
From Pro EJB persistent book:


The result type of a select query is the type corresponding to each row in the result set produced
by executing the query. This may include entities, primitive types and other persistent
attribute types, but never a collection type. The following query is illegal:
SELECT d.employees
FROM Department d


Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
the correct query would be:
select c from Student s join s.courses c
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Thank you krishna.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3324
    
    8
Hi Sergio,
All these queries have been tested on Sun's reference implementation and the query under discussion works as well. I am trying to find an appropriate citation from the specification
[ September 08, 2008: Message edited by: Paul Anil ]

Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Hi Paul,

Thank you. In fact, I did test it using glassfish and it works as stated by Enthuware. However, accordingly to the specification (section 4.8) it shouldn't be the case.

I'll copy the quote here:

Note that the SELECT clause must be specified to return only single-valued expressions. The query below is therefore invalid:
SELECT o.lineItems from Order AS o


BTW, have you taken a look at this other topic? I tested using glassfish and the results were the same as what I was expecting (and different to enthuware's).

And thank you for your support and great product. Other than these two minor doubts, I found your product excellent and absolutely worth the price.
[ September 08, 2008: Message edited by: Sergio Tridente ]
Andrey Karayvansky
Greenhorn

Joined: Feb 18, 2008
Posts: 10
I agree with Sergio, concrete vendor implementation is not an indicator.

There is a mistake in the question.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3324
    
    8
Thanks for the feedback. Additional explanation has now been added that highlights the discrepency between the specification and reference implementation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enthuware question doubt regarding JPQL