Skip to content

Fix limits in polymorphic queries #2618

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 4 commits into from
Jan 14, 2021
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
54 changes: 54 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH2614/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2614
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
protected override void OnSetUp()
{
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
s.Save(new ConcreteClass1 {Name = "C1"});
s.Save(new ConcreteClass2 {Name = "C2"});
t.Commit();
}
}

protected override void OnTearDown()
{
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
s.CreateQuery("delete from System.Object").ExecuteUpdate();
t.Commit();
}
}

[Test]
public async Task PolymorphicListReturnsCorrectResultsAsync()
{
using (var s = OpenSession())
using (s.BeginTransaction())
{
var query = s.CreateQuery(
@"SELECT Name FROM NHibernate.Test.NHSpecificTest.GH2614.BaseClass ROOT");
query.SetMaxResults(5);
var list = await (query.ListAsync());
Assert.That(list.Count, Is.EqualTo(2));
}
}
}
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2614/BaseClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace NHibernate.Test.NHSpecificTest.GH2614
{
public abstract class BaseClass
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2614/ConcreteClass1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace NHibernate.Test.NHSpecificTest.GH2614
{
public class ConcreteClass1 : BaseClass
{
}
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2614/ConcreteClass2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH2614
{
public class ConcreteClass2 : BaseClass
{
}
}
43 changes: 43 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2614/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2614
{
[TestFixture]
public class Fixture : BugTestCase
{
protected override void OnSetUp()
{
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
s.Save(new ConcreteClass1 {Name = "C1"});
s.Save(new ConcreteClass2 {Name = "C2"});
t.Commit();
}
}

protected override void OnTearDown()
{
using (var s = OpenSession())
using (var t = s.BeginTransaction())
{
s.CreateQuery("delete from System.Object").ExecuteUpdate();
t.Commit();
}
}

[Test]
public void PolymorphicListReturnsCorrectResults()
{
using (var s = OpenSession())
using (s.BeginTransaction())
{
var query = s.CreateQuery(
@"SELECT Name FROM NHibernate.Test.NHSpecificTest.GH2614.BaseClass ROOT");
query.SetMaxResults(5);
var list = query.List();
Assert.That(list.Count, Is.EqualTo(2));
}
}
}
}
20 changes: 20 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2614/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="NHibernate.Test.NHSpecificTest.GH2614"
assembly="NHibernate.Test"
>
<class name="ConcreteClass1" >
<id name="Id">
<generator class="increment"/>
</id>
<property name="Name"/>
</class>

<class name="ConcreteClass2" >
<id name="Id">
<generator class="increment"/>
</id>
<property name="Name"/>
</class>

</hibernate-mapping>
2 changes: 1 addition & 1 deletion src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task PerformListAsync(QueryParameters queryParameters, ISessionImpl
for (int x = 0; x < size; x++)
{
object result = tmp[x];
if (distinction.Add(result))
if (!distinction.Add(result))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Engine/Query/HQLQueryPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void PerformList(QueryParameters queryParameters, ISessionImplementor ses
for (int x = 0; x < size; x++)
{
object result = tmp[x];
if (distinction.Add(result))
if (!distinction.Add(result))
{
continue;
}
Expand Down