Meaningless Drivel is fun!
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes JPQL Question with Left Join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "JPQL Question with Left Join" Watch "JPQL Question with Left Join" New topic

JPQL Question with Left Join

Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Question Number 43 of the Diagnostic Exam of WhizLabs preparation kit.

FROM Dept d LEFT JOIN FETCH d.employees
WHERE d.department_no = 1

[A] From the above query only employees of department no 1 will be retrieved.
[B] From the above query those departments will be retrieved which has employee and have department_no not equals to 1.
[C] This will retrieve all the departments, which has department_no equals to 1. It will also retrieve the associated employees with the set of departments.
[D] This is an invalid query.

According to the WhizLabs, the correct answer is C.
Can someone tell me why the answer B is wrong?

Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
First of all because option B says that the departments retrieved will not have id = 1, but the where clause asks for 1. Second, it retrieves the department either if it has any employee, or if it has no employees - it is a left outer join.
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Oh! Thanks Raf.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
So as per this link can we say that the Department is the LEFT entity (table) and Employees is the RIGHT entity (table).

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
I agree. Here's the link:
subject: JPQL Question with Left Join
It's not a secret anymore!