The following is a question that was supposedly part of the official exam from the Sun:
The Reader object is a one-to-many relationship, bidirectional with the Book Object. Two Reader objects are saved, each of which has two books associated with them. For example, reader 1 has book a and book b, while reader 2 has book c and book d. Which query returns a collection of less than four items?
A. SELECT b.reader FROM Book b
B. SELECT from an entry b INPUT JOIN b.reader r
C. SELECT r FROM Reader r INNER JOIN r.books b
D. SELECT r from book b LEFT JOIN b.reader r LEFT JOIN FETCH r.books
This answer is C, which I believe is incorrect. From what I understand, SQL with an inner join of two tables will be generated by the JPA provider. Therefore, in all cases we get 4 entries. I checked the one-to-many test and duplicates were added.
Who is wrong, me or the sun?
source
share