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

Lukas Eder lukas.eder at gmail.com
Thu Feb 22 03:09:49 EST 2018


 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


More information about the hibernate-dev mailing list