This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPQL doubt

 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are 2 entities:

Entity 1:


Entity 2:


Question: out of the following 2 queries, which one will return students who have given only one Presentation?
1. select s from Student s where size(s.presentations)=1
2. select s from Student s where (select count(p) from s.presentations p)=1

According to enthuware the 2nd one is correct.

Should'nt the first option be correct as size(s.presentations) would return the size of the collection as an integer and presentations is a Collection type...???

please help...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although both queries look ok, your code does not. You have two Student entities. Also, did you mean to make the relationship unidirectional ?
 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats my mistake...the 2nd class is Presentation


please help...
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can only use aggregates in select clause with group by and/or having.

you cannot use it in where clause.

refer to BNF in Mikalai's notes or specs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic