[hibernate-dev] Why does implicit join translate to inner join?

Lukas Eder lukas.eder at gmail.com
Thu Feb 22 05:05:33 EST 2018


Sure, there may be a chicken and egg situation between Hibernate and JPA,
but I'm trying to understand why this was specified the way it is, as I
find this quite surprising.

2018-02-22 10:59 GMT+01:00 andrea boriero <andrea at hibernate.org>:

> Hi Lukas,
>
> I think it is based on JPA 2.1 spec, 4.4.4 Path Expressions , "Path
> expression navigability is composed using “inner join” semantics."
>
> On 22 February 2018 at 08:09, Lukas Eder <lukas.eder at gmail.com> wrote:
>
>>  Hello,
>>
>> Vlad Mihalcea [1] was so kind to point me to this mailing list with my
>> question about implicit joins. The user guide [2] states that:
>>
>>   "Implicit joins are always treated as inner joins."
>>
>> To me, this seems wrong, semantically, if implicit joins follow optional
>> (nullable) foreign key relationships. Let's assume that customers have
>> optional addresses. When we write
>>
>>   SELECT c.firstName, c.lastName, c.address.city.country.code
>>   FROM customer c
>>
>> The resulting query will INNER JOIN the customer / address / city /
>> country
>> tables, filtering out customers with no address, or addresses with no
>> cities, or cities with no countries (let's ignore the modelling aspect).
>> In
>> fact, I got a CROSS JOIN with join predicate in the WHERE clause, but that
>> doesn't really change anything. Hence the SELECT clause applies a filter,
>> which is rather surprising. To me, this seems simply wrong just like it
>> would be wrong for Stream.map() to apply any filters.
>>
>> However, I'm sure there must have been good reasons to default to this
>> behaviour, even in the presence of optional foreign keys.
>>
>> Does anyone know what those reasons are?
>> Cheers,
>> Lukas
>>
>> [1]: https://twitter.com/vlad_mihalcea/status/965927462684196864
>> [2]: http://docs.jboss.org/hibernate/orm/5.2/userguide/
>> html_single/Hibernate_User_Guide.html#hql-implicit-join
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>
>
>


More information about the hibernate-dev mailing list