jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: outer joins with ON conditions

From: Emmanuel Bernard <emmanuel.bernard_at_jboss.com>
Date: Tue, 15 Mar 2011 19:08:43 +0100

How would you differentiate when a user wants to:

 - add to the implicit ON clause
JP-QL = FROM Cat as cat LEFT JOIN cat.kittens as kitten ON kitten.bodyWeight > 10.0
SQL = from Cat c OUTER JOIN Cat k ON c.id = k.parent AND k.bodyWeight > 10.0

 - full replacement of the ON clause
JP-QL = FROM Cat as cat LEFT JOIN cat.kittens as kitten ON kitten.bodyWeight > 10.0 AND kitten.parentName = cat.name
SQL = from Cat c OUTER JOIN Cat k ON c.name = k.parentName AND k.bodyWeight > 10.0 //note that c.id and k.parent are not in the ON clause of the SQL equivalent

Emmanuel


On 15 mars 2011, at 18:57, Linda DeMichiel wrote:

> I still don't see why a separate keyword is needed for this.
>
> On 3/15/2011 10:55 AM, Emmanuel Bernard wrote:
>> On 15 mars 2011, at 17:51, Linda DeMichiel wrote:
>>> On 3/15/2011 3:31 AM, Emmanuel Bernard wrote:
>>>> The doc is minimal, I'm pasting it for info
>>>> You may supply extra join conditions using the HQL with keyword.
>>>> from Cat as cat
>>>> left join cat.kittens as kitten
>>>> with kitten.bodyWeight > 10.0
>>>> <<<
>>>> http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/queryhql.html#queryhql-joins
>>>> this essentially concatenate an SQL version of kitten.bodyWeight > 10.0 to the rest of the SQL ON clause used to auto join the Cat table.
>>>> My email was really a question, I wanted to confirm that what you were proposing was essentially the same concept.
>>> Thanks -- yes.
>>>
>>>> As for a full ON clause replacement, a few users and customers have requested it over the years. But we have not implemented such a feature yet. I suspect people are willing to do adhoc joins even across non mapped associations. I see it as much less useful than the proposed feature.
>>> Same here. We could add it later if requested.
>> OK nice. So the reason for proposing a different keyword than ON for the "add-on" ON clause was to leave the door open for the full fledge ON replacement. In Hibernate we use WITH.
>> Emmanuel