Using identification variables with is empty resolves in a broken query

Description

See the test case for details, but basically, I was trying to create a HQL query that would return a parent object if either its sub-objects matched on a name, or it had no links to its sub-objects. I mistakenly used the identification variable in an is empty instead of the actual collection because I misunderstood that the identification variable is the single object in the collection, not an alias for the collection itself. Whilst this is not the bug, what I believe is the bug, is that hibernate went on to create this sql query:

Instead of just erroring or at least throwing a warning saying that I was using invalid syntax. The problem with this query is that if you look closely at the first where fragment, it will always return true for exists (..), so it will always return false when used in the not(..), therefore will never return any Cars with no parts. This obviously does this logically not make any sense at all if you've not twigged you're using the hql wrong.

Maybe this will not be agreed with, but I feel like what was happening was very unexpected to the user, and this situation would be greatly improved if hibernate could detect whether someone was using a non collection or collection identification variable in an is [not] empty fragment (or indeed any other collection-related fragments).

Environment

Using hibernate orm template

Assignee

Unassigned

Reporter

James Reed

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure