Skip to content

Commit

Permalink
Fix mixing implied implicit and left joins in hql (nhibernate#3187)
Browse files Browse the repository at this point in the history
5.3 specific fix
Fixes nhibernate#3185
  • Loading branch information
bahusoid authored Jan 15, 2023
1 parent 37b5020 commit 70dffa3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
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

0 comments on commit 70dffa3

Please sign in to comment.