• 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
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Another Enthuware question doubt regarding JPQL

 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have some doubts regarding the following question:

Given the following two entites:




Given further that the following data exists in the database:
Student John refers to Presentations P1 and P2
Student Jacob refers to Presentations P3 and P4

Write the sizes of collections returned by the following queries:

1. SELECT p.presenter from Presentation p
Ans: 4
My answer: 4

2. SELECT s from Presentation p INNER JOIN p.presenter s
Ans: 4
My answer: 4

3. SELECT s from Student s INNER JOIN s.presentations p
Ans: 2
My answer: 4

4. SELECT s from Presentation p LEFT JOIN p.presenter s LEFT JOIN FETCH s.presentations
Ans: 4
My answer: 8


I agree with the answer given for the first two statements but not eith the other two.

This is my reasoning:

3. SELECT s from Student s INNER JOIN s.presentations p
Even if only Student instances are returned by the JPQL statement, there is an inner join with Presentations. So, how come only two rows will be returned?
From my point of view, changing the query as "SELECT s, p from Student s INNER JOIN s.presentations p" will make it more obviuos that 4 rows are returned.

4. SELECT s from Presentation p LEFT JOIN p.presenter s LEFT JOIN FETCH s.presentations

In this case we are joining Presentation with Student and again with Presentation. Presentation with Student returns 4 rows and then each one of this 4 rows is joined with Presentation again. Taking into consideration that each Student refers to two Presentations, we should get a result of 8 rows (4 x 2).

Am I correct?

Thanks in advance.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic