Skip to content

HqlParser does not correctly negate EXISTS-nodes below an AND/OR #3327

@csharper2010

Description

@csharper2010

For the not explicitly handled cases in HqlParser.NegateNode, a new node is created but AND/OR do not correctly replace the children with the newly created ones.

This leads to wrong sql query.

Example base query (correctly handled):

SELECT COUNT(ROOT.Id)
FROM Entity AS ROOT
WHERE (
    EXISTS (FROM ChildEntity AS CHILD WHERE CHILD.Parent = ROOT)
    AND ROOT.Name = 'Test'
)

Example base query (wrong):

SELECT COUNT(ROOT.Id)
FROM Entity AS ROOT
WHERE NOT (
    EXISTS (FROM ChildEntity AS CHILD WHERE CHILD.Parent = ROOT)
    AND ROOT.Name = 'Test'
)

Pull request is created. Problem is obvious and the fix straightforward.
As someone has stated, a similar bugfix was made in Hibernate.

I would appreciate addition to next 5.4.x release.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions