jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: outer fetch joins with on-conditions

From: Steve Ebersole <steve.ebersole_at_redhat.com>
Date: Thu, 01 Nov 2012 08:08:52 -0500

I was not able to respond on the issue, so replying here...

It can lead to *incomplete* state, yes. And not just for outer join
fetches, but even inner join fetches as well.

So you are correct about the grammar not allowing to assign an
identification variable (alias) to an outer join. So by spec this
should not be an issue with outer joins per-se. Hibernate for example
though does allow aliasing the outer join.

But like I said, the same is true of inner joins as well. So using his
domain model, if you say:

select p from Person p inner join fetch p.addresses a on a.primary =
true

You have just filtered out non-primary addresses from the fetched
graph, so the Person graph is incomplete as it is missing its
non-primary addresses.

The graph is *incomplete*, it is not necessarily inconsistent. The
"inconsistency" really comes down to how the provider handles the
collection at flush time.

If we restrict ON-conditions [still can't convince you to rename that
to WITH? ;)] at all, I think the illegality should be in conjunction
with join fetches of any sort.

There is even insidious little things to consider as well, like imagine
that Address had a further association City which has a [boolean
top100] attribute:

select p from Person p inner join fetch p.addresses a where
a.city.top100 = true

This again leads to incomplete results. So it is not strictly limited
to ON conditions. Its related to any form of restriction on a join
fetched association.


On Wed 31 Oct 2012 02:51:29 PM CDT, Linda DeMichiel wrote:
> I've been having an interesting discussion with a user on the JPA JIRA
> with
> regard to outer fetch joins. See the issue
> http://java.net/jira/browse/JPA_SPEC-40
>
> The issue is basically whether an outer fetch join with on-condition
> can result in an entity whose state/relationships have been
> inconsistently
> fetched.
>
> Since we don't currently support the use of identification variables on
> the right hand side, I believe that we currently do not have a problem.
> Please double-check whether you agree with me on this or not.
>
> However, the ability to specify identification variables here has also
> be requested,
> and is something that we could plausibly add in future. See the issue
> http://java.net/jira/browse/JPA_SPEC-28
>
> I'd like input from the group with regard to these issue, and whether
> we should consider:
>
> 1) not supporting outer fetch joins with on-conditions
> 2) not (i.e., never) supporting outer fetch joins with the use of
> identification
> variables on the right hand side
> 3) not supporting the use of on-conditions with outer fetch joins that
> use
> identification variables on the right hand side.
> 4) other??
>
> -Linda