This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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.
 
Always look on the bright side of life. At least this ad is really tiny:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!