OneToMany association with @NotFound results in SQL with different JOIN-type for SELECT (LEFT JOIN) and COUNT (JOIN)

Description

I have the situation where I need to remember the FK (java.lang.Long) of a OneToMany association, even if the associated entity does not exist anymore on the database. In order to achieve this, I map the FK as a property and also as OneToMany with @NotFound(IGNORE). In case the associated entity does no longer exist on the db, its ID is still available as Long property on the one-side.
If I do a COUNT on the database (by JPA criteria or JPQL) for all entites where the associated entity IS NULL, I expect to get a number equal to the result-size of an equivalent SELECT, but this is not the case.
This is because the SELECT is genereated with LEFT JOIN on the associated table and COUNT with JOIN only.
If I omitt the @NotFound, everything is fine in respect to the generated SQL as no JOIN clause seems to be generated at all.

Attachments

1

follows up on

Activity

Show:
Fixed

Details

Assignee

Reporter

Worked in

Sprint

Fix versions

Affects versions

Priority

Created November 3, 2023 at 2:47 PM
Updated December 1, 2023 at 5:11 PM
Resolved November 10, 2023 at 8:31 AM