Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Enthuware question doubt regarding JPQL

 
Ranch Hand
Posts: 329
Oracle Java Linux
  • 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 ]
 
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
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you krishna.
 
Enthuware Software Support
Posts: 4430
41
  • 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
Oracle Java Linux
  • 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 ]
 
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
Posts: 4430
41
  • 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.
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic