Render nullness-check for inverse one-to-one as exists subquery

Description

Consider the two entities:

and

The JPQL-query "from Parent p where p.child is null" should list all parents that don't have a child.
The actual SQL that is generated looks like this:

This query always returns an empty result, because the pk of person is never null!

Testcase:

Activity

Show:
Adrodoc
June 26, 2018, 1:29 PM

Btw, here is another strong argument which indicates that "bug" is the correct term:
If you use the query

you get the following SQL statement:

This returns all persons instead of just those with children.

Christian Beikov
June 26, 2018, 3:55 PM

Thanks for creating the report, but please stop arguing whether it's a bug or not. It's not clear from the spec and since we don't have an implementation of this to check against the TCK, we don't know if this is a valid interpretation. The behavior for "owned" associations you are referring is apparently valid, otherwise Hibernate wouldn't be JPA compliant. For non-owned assocations, we don't know yet. So, provide the PR, and then we can talk about details

Adrodoc
June 26, 2018, 5:43 PM

I am sorry. I don't actually care whether you call this a bug, an enhancement or an improvement. I just wanted to point out that unlike the original query, which does not make sense if you regard the where clause as an implicit and therefor inner join, the query using `is not null` would work perfectly fine if an inner join was generated. So the argument against the validity of the original where clause does not hold in case of this modified where clause, because the path p.child is not null.

Adrodoc
June 26, 2018, 5:55 PM

Also in case of `is not null` EclipseLinks Query is actually correct, so my previous statement that EclipseLink and Hibernate are either both correct or incorrect is not true for this modified query.

Alex Zaytsev
March 26, 2019, 11:04 AM

Assignee

Unassigned

Reporter

Adrodoc

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure