Skip to content

Fix #1228 #2146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2019
Merged

Fix #1228 #2146

merged 1 commit into from
Jul 16, 2019

Conversation

csharper2010
Copy link
Contributor

NH-2648 - HQL with joins in sub-select creates wrong SQL
Join in subselect based on alias for item in root select was not added
This fixes the specific case in the least risky way, all tests green

Signed-off-by: csharper2010 csharper2010@googlemail.com

NH-2648 - HQL with joins in sub-select creates wrong SQL
Join in subselect based on alias for item in root select was not added
This fixes the specific case in the least risky way, all tests green

Signed-off-by: csharper2010 <csharper2010@googlemail.com>
@@ -736,6 +736,11 @@ void PrepareFilterParameter()

HandleWithFragment(fromElement, with);
}

if (fromElement.Parent == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be done where the fromElement is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but there are cases where the item is added to the tree explicitly in FromElement.SetOrigin but there is an else branch with comment
// Otherwise, the destination node was implied by the FROM clause and the FROM clause processor // will automatically add it in the right place.

But at least for the implied join in an explicit join no code took care of adding the item to the tree.

I tried to identify the case and go to the previous else if branch (where the comment HHH-276 is located) but that caused one legacy unit test to fail.

As there is no clear responsibility for how the element should be added to the tree, I found it most easy to add it where I did. It's some kind of catch all cases where the item is not added yet which one can find good or bad. But as I said, there is no clear responsibility so I tended towards the feeling: it's a good thing.

@hazzik hazzik merged commit 89e4422 into nhibernate:master Jul 16, 2019
@hazzik hazzik added this to the 5.3 milestone Jul 16, 2019
@bahusoid
Copy link
Member

bahusoid commented Jan 15, 2022

#1228 is invalid issue.

FROM Entity e JOIN e.Parent

This query makes sense. JOIN e.Parent instructs INNER JOIN Parent table using association columns specified in Entity.Parent mapping.

Query from issue:

FROM Entity e WHERE EXISTS ( FROM AnotherEntity JOIN e.Parent WHERE ...)

Here JOIN e.Parent doesn't make any sense. There is no association between AnotherEntity and e.Parent so inner join can't be generated.

This fix makes it generated as implicit joins. To me exception looks more appropriate here..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants