posted 8 years ago

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.

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.

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)