Skip to content

Fix mixing implied implicit and left joins in HQL for v5.3 #3187

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 3 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build-common/NHibernate.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<PropertyGroup>
<NhVersion Condition="'$(NhVersion)' == ''" >5.3</NhVersion>
<VersionPatch Condition="'$(VersionPatch)' == ''">14</VersionPatch>
<VersionPatch Condition="'$(VersionPatch)' == ''">15</VersionPatch>
<!-- Clear VersionSuffix for making release and set it to dev for making development builds -->
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''">dev</VersionSuffix>

<VersionPrefix Condition="'$(VersionPrefix)' == ''">$(NhVersion).$(VersionPatch)</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)' != '' AND '$(BuildNumber)' != ''">$(VersionSuffix).$(BuildNumber)</VersionSuffix>
Expand Down
4 changes: 4 additions & 0 deletions src/NHibernate.Test/Async/Hql/EntityJoinHqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,17 @@ from x2 in session.Query<NullableOwner>()
var withNullOrValidList = await (session.Query<NullableOwner>().Where(x => x.ManyToOne.Id == validManyToOne.Id || x.ManyToOne == null).ToListAsync());
var withNullOrValidList2 = await (session.Query<NullableOwner>().Where(x => x.ManyToOne == null || x.ManyToOne.Id == validManyToOne.Id).ToListAsync());

//GH-3185
var mixImplicitAndLeftJoinList = await (session.Query<NullableOwner>().Where(x => x.ManyToOne.Id == validManyToOne.Id && x.OneToOne == null).ToListAsync());

Assert.That(fullList.Count, Is.EqualTo(2));
Assert.That(withValidManyToOneList.Count, Is.EqualTo(0));
Assert.That(withValidManyToOneList2.Count, Is.EqualTo(0));
Assert.That(withNullManyToOneList.Count, Is.EqualTo(2));
Assert.That(withNullManyToOneJoinedList.Count, Is.EqualTo(2));
Assert.That(withNullOrValidList.Count, Is.EqualTo(2));
Assert.That(withNullOrValidList2.Count, Is.EqualTo(2));
Assert.That(mixImplicitAndLeftJoinList.Count, Is.EqualTo(1));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/NHibernate.Test/Hql/EntityJoinHqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,17 @@ from x2 in session.Query<NullableOwner>()
var withNullOrValidList = session.Query<NullableOwner>().Where(x => x.ManyToOne.Id == validManyToOne.Id || x.ManyToOne == null).ToList();
var withNullOrValidList2 = session.Query<NullableOwner>().Where(x => x.ManyToOne == null || x.ManyToOne.Id == validManyToOne.Id).ToList();

//GH-3185
var mixImplicitAndLeftJoinList = session.Query<NullableOwner>().Where(x => x.ManyToOne.Id == validManyToOne.Id && x.OneToOne == null).ToList();

Assert.That(fullList.Count, Is.EqualTo(2));
Assert.That(withValidManyToOneList.Count, Is.EqualTo(0));
Assert.That(withValidManyToOneList2.Count, Is.EqualTo(0));
Assert.That(withNullManyToOneList.Count, Is.EqualTo(2));
Assert.That(withNullManyToOneJoinedList.Count, Is.EqualTo(2));
Assert.That(withNullOrValidList.Count, Is.EqualTo(2));
Assert.That(withNullOrValidList2.Count, Is.EqualTo(2));
Assert.That(mixImplicitAndLeftJoinList.Count, Is.EqualTo(1));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,13 @@ public void SetOrigin(FromElement origin, bool manyToMany)
}
else
{
if (!Walker.IsInFrom && !Walker.IsInSelect)
if (Walker.IsInFrom || Walker.IsInSelect || (this.IsImplied && !this.JoinSequence.IsThetaStyle))
{
FromClause.AddChild(this);
origin.AddChild(this);
}
else
{
origin.AddChild(this);
FromClause.AddChild(this);
}
}
}
Expand Down