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 doubt on JPQL

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have the following doubts from enthuware.

1)

Consider the following entities -

@Entity public class Student{
...
String firstname;
@OneToMany
Collection<Presentation> presentations;
...
}

@Entity public class Presentation{
...
}

Which of the following JPQL queries will return the firstname and the number of presentations that a student has made?


Please select 1 option

a)select s.firstname, count(s.presentations) from Student s
b)select s.firstname, count(s.presentations) from Student s group by s.firstname
c)select s.firstname, count(s.presentations) from Student s group by s.presentations
d)select s.firstname, count(p) from Student s left join s.presentations p

The right answer for this one is option b.


My doubt is how can we select count(s.presentations) directly as specified in option b.

Because the spec says "it is illegal to select elements directly from a collection-based relationship."


Thanks in advance

With Regards
Deepthi


 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just quessing..but I think that the spec means that you musn't try to do something like:


 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a minute I'm wrong...what you said is correct..you can't access an element in a collection at all in a JPQL query...But in your example the collection is not actually being accessed...an aggregate function(I think count is an aggregate function) is just being applied to the collection as a whole.So the correct answer is b.
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic