users@glassfish.java.net

Re: A query with LEFT JOIN FETCH returns duplicates when it shouldn't

From: <glassfish_at_javadesktop.org>
Date: Fri, 02 Mar 2007 07:04:21 PST

Hi Witold,

I think the spec reads different. Chapter 4.4.5.3 Fetch Joins on page 86 says:
"A fetch join has the same join semantics as the corresponding inner or outer join, except that the related objects specified on the right-hand side of the join operation are not returned in the query result or otherwise referenced in the query. Hence, for example, if department 1 has five employees, the above query returns five references to the department 1 entity".

The last sentence refers to the following sample query which is very similar to yours:
SELECT d FROM Department d LEFT JOIN FETCH d.employees WHERE d.deptno = 1

So I think you have to use DISTINCT to make sure the query returns only a single reference.

Regards Michael
[Message sent by forum member 'mb124283' (mb124283)]

http://forums.java.net/jive/thread.jspa?messageID=205984