This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enthuware question doubt regarding JPQL

 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the correct query would be:
select c from Student s join s.courses c
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you krishna.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3776
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3776
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the feedback. Additional explanation has now been added that highlights the discrepency between the specification and reference implementation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic