Yes, the syntax is something like this:
[LEFT[OUTER]|INNER]JOIN FETCH
So you are looking for "LEFT JOIN FETCH", not just "LEFT JOIN".
I.e. "FETCH" is what does the prefetching of a relationship, and the
rest is specifying the join semantics and can be used with or without
prefetching.
Andrus
On May 6, 2010, at 1:02 PM, Andrew Lindesay wrote:
Hi Andrus;
Thanks for the suggestion. I did try that with this;
SELECT u FROM FooBar u OUTER JOIN u.someToMany c WHERE u.userType
= :userType ORDER BY u.username
I get the following exception;
Caused by: org.apache.cayenne.ejbql.parser.ParseException:
Encountered " "OUTER" "OUTER "" at line 1, column 25.
Was expecting one of:
<EOF>
"," ...
"ORDER" ...
"WHERE" ...
"GROUP" ...
"HAVING" ...
"LEFT" ...
"INNER" ...
"JOIN" ...
at
org
.apache.cayenne.ejbql.parser.EJBQL.generateParseException(EJBQL.java:
9419)
at
org.apache.cayenne.ejbql.parser.EJBQL.jj_consume_token(EJBQL.java:
9298)
I also tried a LEFT JOIN which I think would do what I want and it
certainly picks up the rows as I would anticipate from the SQL log,
but the to-many doesn't seem to freshen.
cheers.
IIRC there's also an OUTER fetch join that handles this case.
...
yeah, you can use fetch joins (since 3.0). something like
select f FROM FooBar f inner join fetch f.bars b ...
...
I tried that and it produces a query which excludes objects from
the result-set where there is nothing in the join. The behaviour
of "query.addPrefetch(..)" would be to run two SELECT database
queries to get the additional data and freshen-up the relationship
if my thinking is correct.
___
Andrew Lindesay
www.silvereye.co.nz