JPA – jpql: internal connection has no duplicate records
The following is a question that is said to be part of sun's official exam:
Since the answer is C, I don't think it is correct As far as I know, the JPA provider will generate SQL for the inner join of the two tables Therefore, in all cases, we will get 4 records I have tested the one - to - many relationship and included duplicates
Who's wrong, me or the sun?
Solution
The answer comes from Mike Keith, director of EJB 3.0 common specification:
There are two statements related to repetition in the specification
>Join fetch is a variant of join, but it does indicate that similar join semantics apply (except that more data is selected) The specification (section 4.4.5.3 of JPA V2.0) gives an example of returning duplicate Department lines, although the employee object is not in the select clause. > A more direct reference is in the select section (section 4.8 of JPA V2.0), which makes this clear
If distinct is not specified, duplicate values will not be de duplicated
In fact, many JPA providers do delete duplicates for the following reasons:
a) Convenience for users, because some users do not know enough in SQL and do not expect them. B) there are usually no use cases that need to be repeated. C) they can be added to the result set. If the object ID is maintained, the duplication will be automatically eliminated