Skip to content

Commit a958ff1

Browse files
Fix Clear forgetting the non lazy collections (#3482)
1 parent 0978f4c commit a958ff1

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 System.Collections.Generic;
12+
using System.Linq;
13+
using NHibernate.Linq;
14+
using NUnit.Framework;
15+
16+
namespace NHibernate.Test.NHSpecificTest.GH3424
17+
{
18+
using System.Threading.Tasks;
19+
[TestFixture]
20+
public class FixtureAsync : BugTestCase
21+
{
22+
protected override void OnSetUp()
23+
{
24+
using var session = OpenSession();
25+
using var transaction = session.BeginTransaction();
26+
27+
var c1 = new Child { Name = "Rob" };
28+
session.Save(c1);
29+
var e1 = new Entity { Name = "Bob", Children = new HashSet<Child> { c1 } };
30+
session.Save(e1);
31+
32+
transaction.Commit();
33+
}
34+
35+
protected override void OnTearDown()
36+
{
37+
using var session = OpenSession();
38+
using var transaction = session.BeginTransaction();
39+
session.CreateQuery("delete Child").ExecuteUpdate();
40+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
41+
42+
transaction.Commit();
43+
}
44+
45+
[Test]
46+
public async Task QueryingAfterFutureThenClearAsync()
47+
{
48+
using var session = OpenSession();
49+
using var transaction = session.BeginTransaction();
50+
var futureBob = session.Query<Entity>().Where(e => e.Name == "Bob").ToFutureValue(q => q.FirstOrDefault());
51+
var bob = await (futureBob.GetValueAsync());
52+
Assert.That(bob, Is.Not.Null);
53+
session.Clear();
54+
55+
var allQuery = session.Query<Entity>();
56+
Assert.That(() => allQuery.ToListAsync(), Has.Count.EqualTo(1));
57+
await (transaction.CommitAsync());
58+
}
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3424
5+
{
6+
class Entity
7+
{
8+
public virtual Guid Id { get; set; }
9+
public virtual string Name { get; set; }
10+
public virtual ISet<Child> Children { get; set; }
11+
}
12+
13+
class Child
14+
{
15+
public virtual Guid Id { get; set; }
16+
public virtual string Name { get; set; }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NHibernate.Linq;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH3424
7+
{
8+
[TestFixture]
9+
public class Fixture : BugTestCase
10+
{
11+
protected override void OnSetUp()
12+
{
13+
using var session = OpenSession();
14+
using var transaction = session.BeginTransaction();
15+
16+
var c1 = new Child { Name = "Rob" };
17+
session.Save(c1);
18+
var e1 = new Entity { Name = "Bob", Children = new HashSet<Child> { c1 } };
19+
session.Save(e1);
20+
21+
transaction.Commit();
22+
}
23+
24+
protected override void OnTearDown()
25+
{
26+
using var session = OpenSession();
27+
using var transaction = session.BeginTransaction();
28+
session.CreateQuery("delete Child").ExecuteUpdate();
29+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
30+
31+
transaction.Commit();
32+
}
33+
34+
[Test]
35+
public void QueryingAfterFutureThenClear()
36+
{
37+
using var session = OpenSession();
38+
using var transaction = session.BeginTransaction();
39+
var futureBob = session.Query<Entity>().Where(e => e.Name == "Bob").ToFutureValue(q => q.FirstOrDefault());
40+
var bob = futureBob.Value;
41+
Assert.That(bob, Is.Not.Null);
42+
session.Clear();
43+
44+
var allQuery = session.Query<Entity>();
45+
Assert.That(() => allQuery.ToList(), Has.Count.EqualTo(1));
46+
transaction.Commit();
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH3424">
4+
5+
<class name="Entity">
6+
<id name="Id" generator="guid.comb"/>
7+
<property name="Name"/>
8+
<set name="Children" lazy="false">
9+
<key column="EntityId"/>
10+
<one-to-many class="Child" />
11+
</set>
12+
</class>
13+
14+
<class name="Child">
15+
<id name="Id" generator="guid.comb"/>
16+
<property name="Name"/>
17+
</class>
18+
19+
</hibernate-mapping>

src/NHibernate/Engine/StatefulPersistenceContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ public void Clear()
264264
entityEntries.Clear();
265265
entitySnapshotsByKey.Clear();
266266
collectionsByKey.Clear();
267+
nonlazyCollections.Clear();
267268
collectionEntries.Clear();
268269
if (unownedCollections != null)
269270
{

0 commit comments

Comments
 (0)