users@jpa-spec.java.net

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

From: Linda DeMichiel <linda.demichiel_at_oracle.com>
Date: Tue, 06 Nov 2012 13:48:59 -0800

On 11/1/2012 6:08 AM, Steve Ebersole wrote:
> 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
>

Note that the spec doesn't allow the identification variable on the right hand side here either

> 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.
>

OK. I agree with this.

> 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.
>

Thanks for your helpful analysis.

-LInda


>
> 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