• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Another Enthuware question doubt regarding JPQL

 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic