persistence@glassfish.java.net

Re: Is it legal to have a JPQL query that has multiple LEFT JOIN FETCHes?

From: Tom Ware <tom.ware_at_Oracle.com>
Date: Mon, 19 Feb 2007 16:27:18 -0500

Hi Jon,

  I am a bit surprised you are seeing an issue with the query you list
below.

  Our test framework has some similar queries that work. For instance:

"SELECT e from Employee e JOIN FETCH e.projects"

  Is the exception trace for your current query the same as for the
previous query?

BTW: I took a quick look at the BNF for JPQL and it seems your double
joining query is not legal. JPQL requires a range_variable_declaration
for each fetch join. That means:
Item i LEFT JOIN FETCH i.reservations

Is Legal

And the second part:

LEFT JOIN FETCH i.subItems
Is missing something. (you can't join to "Item i" from the previous clause)

-Tom


Jon Miller wrote:

>I just tried the following which throws a NPE too. So, it looks like it's
>probably the fact that I'm mapping to the same class rather than the fact
>that I had two LEFT JOINs which is what I thought might have been the
>original problem. Is this a bug?
>
>SELECT i FROM Item i LEFT JOIN FETCH i.subItems ORDER BY i.name
>
>Jon
>
>

-- 
Tom Ware
Principal Software Engineer
Oracle Canada Inc.
Direct: (613) 783-4598
Email: tom.ware_at_oracle.com