Multiple SQL select statements for JPQL select with multiple left join fetch

2 Messages Forum Options Options
Embed this topic
Permalink
Don T
Multiple SQL select statements for JPQL select with multiple left join fetch
Reply Threaded MoreMore options
Print post
Permalink
Hi, when running a JPQL query for OpenJPA 1.0.2 with multiple left outer join fetch clauses such as:

SELECT x FROM Magazine x left outer join fetch x.articles left outer join fetch x.authors WHERE x.title = 'JDJ'

it seems multiple SQL select statements are executed, 1 for each join fetch clause. Calling getResultList returns the result set of the last select statement. In the above statement, for example, I see articles is null, but authors is not null. Wondering if this is a known issue and if there are workarounds?
Pinaki Poddar
Re: Multiple SQL select statements for JPQL select with multiple left join fetch
Reply Threaded MoreMore options
Print post
Permalink
Hi,
> SELECT x FROM Magazine x left outer join fetch x.articles left outer join fetch x.authors WHERE x.title = 'JDJ'

  Yes, OpenJPA will run two parallel queries for this case.
  However, the results of the parallel queries are merged. So, for example, if the database contains a single Magazine with title 'JDJ', the query.getResultList() will return a list of size 1, though the query will issue 2 SQL statements. Either of authors or articles of that Magazine instance can be null but that will not affect the result of the query. However, as a side-effect of executing the query the associated authors/articles, if any, will be fetched.

  If you are seeing any different behavior, please post an example.