Skip to content

Commit 2b1af8f

Browse files
authored
Fix limits in polymorphic queries (#2618)
Results from the query should be skipped if they are already in the ISet distinction thus if distinction.Add is false. Currently, they are only added if they have been there before. Fixes #2614
1 parent 7c1a2cd commit 2b1af8f

File tree

8 files changed

+141
-2
lines changed

8 files changed

+141
-2
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using NUnit.Framework;
12+
13+
namespace NHibernate.Test.NHSpecificTest.GH2614
14+
{
15+
using System.Threading.Tasks;
16+
[TestFixture]
17+
public class FixtureAsync : BugTestCase
18+
{
19+
protected override void OnSetUp()
20+
{
21+
using (var s = OpenSession())
22+
using (var t = s.BeginTransaction())
23+
{
24+
s.Save(new ConcreteClass1 {Name = "C1"});
25+
s.Save(new ConcreteClass2 {Name = "C2"});
26+
t.Commit();
27+
}
28+
}
29+
30+
protected override void OnTearDown()
31+
{
32+
using (var s = OpenSession())
33+
using (var t = s.BeginTransaction())
34+
{
35+
s.CreateQuery("delete from System.Object").ExecuteUpdate();
36+
t.Commit();
37+
}
38+
}
39+
40+
[Test]
41+
public async Task PolymorphicListReturnsCorrectResultsAsync()
42+
{
43+
using (var s = OpenSession())
44+
using (s.BeginTransaction())
45+
{
46+
var query = s.CreateQuery(
47+
@"SELECT Name FROM NHibernate.Test.NHSpecificTest.GH2614.BaseClass ROOT");
48+
query.SetMaxResults(5);
49+
var list = await (query.ListAsync());
50+
Assert.That(list.Count, Is.EqualTo(2));
51+
}
52+
}
53+
}
54+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH2614
2+
{
3+
public abstract class BaseClass
4+
{
5+
public virtual int Id { get; set; }
6+
public virtual string Name { get; set; }
7+
}
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH2614
2+
{
3+
public class ConcreteClass1 : BaseClass
4+
{
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Collections.Generic;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH2614
4+
{
5+
public class ConcreteClass2 : BaseClass
6+
{
7+
}
8+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NUnit.Framework;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH2614
4+
{
5+
[TestFixture]
6+
public class Fixture : BugTestCase
7+
{
8+
protected override void OnSetUp()
9+
{
10+
using (var s = OpenSession())
11+
using (var t = s.BeginTransaction())
12+
{
13+
s.Save(new ConcreteClass1 {Name = "C1"});
14+
s.Save(new ConcreteClass2 {Name = "C2"});
15+
t.Commit();
16+
}
17+
}
18+
19+
protected override void OnTearDown()
20+
{
21+
using (var s = OpenSession())
22+
using (var t = s.BeginTransaction())
23+
{
24+
s.CreateQuery("delete from System.Object").ExecuteUpdate();
25+
t.Commit();
26+
}
27+
}
28+
29+
[Test]
30+
public void PolymorphicListReturnsCorrectResults()
31+
{
32+
using (var s = OpenSession())
33+
using (s.BeginTransaction())
34+
{
35+
var query = s.CreateQuery(
36+
@"SELECT Name FROM NHibernate.Test.NHSpecificTest.GH2614.BaseClass ROOT");
37+
query.SetMaxResults(5);
38+
var list = query.List();
39+
Assert.That(list.Count, Is.EqualTo(2));
40+
}
41+
}
42+
}
43+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
namespace="NHibernate.Test.NHSpecificTest.GH2614"
4+
assembly="NHibernate.Test"
5+
>
6+
<class name="ConcreteClass1" >
7+
<id name="Id">
8+
<generator class="increment"/>
9+
</id>
10+
<property name="Name"/>
11+
</class>
12+
13+
<class name="ConcreteClass2" >
14+
<id name="Id">
15+
<generator class="increment"/>
16+
</id>
17+
<property name="Name"/>
18+
</class>
19+
20+
</hibernate-mapping>

src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task PerformListAsync(QueryParameters queryParameters, ISessionImpl
7878
for (int x = 0; x < size; x++)
7979
{
8080
object result = tmp[x];
81-
if (distinction.Add(result))
81+
if (!distinction.Add(result))
8282
{
8383
continue;
8484
}

src/NHibernate/Engine/Query/HQLQueryPlan.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void PerformList(QueryParameters queryParameters, ISessionImplementor ses
128128
for (int x = 0; x < size; x++)
129129
{
130130
object result = tmp[x];
131-
if (distinction.Add(result))
131+
if (!distinction.Add(result))
132132
{
133133
continue;
134134
}

0 commit comments

Comments
 (0)