Skip to content

Commit ceb7a9e

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
GH2201: Change order of deletes in EntityWithMutableCollection tests to avoid the StaleObjectStateException due Parties being loaded and deleted with the Contract in the One-to-Many case.
1 parent 56c1bb8 commit ceb7a9e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/NHibernate.Test/Async/Immutable/EntityWithMutableCollection/AbstractEntityWithOneToManyTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,8 @@ public virtual async Task OneToManyCollectionOptimisticLockingWithUpdateAsync()
12351235
s = OpenSession();
12361236
t = s.BeginTransaction();
12371237
c = await (s.CreateCriteria<Contract>().UniqueResultAsync<Contract>());
1238+
await (s.DeleteAsync(c));
1239+
12381240
// If the entity uses a join mapping, DML queries require temp tables.
12391241
if (Dialect.SupportsTemporaryTables)
12401242
await (s.CreateQuery("delete from Party").ExecuteUpdateAsync());
@@ -1252,7 +1254,6 @@ public virtual async Task OneToManyCollectionOptimisticLockingWithUpdateAsync()
12521254
await (s.DeleteAsync(newParty));
12531255
}
12541256

1255-
await (s.DeleteAsync(c));
12561257
Assert.That(await (s.CreateCriteria<Contract>().SetProjection(Projections.RowCountInt64()).UniqueResultAsync<long>()), Is.EqualTo(0L));
12571258
Assert.That(await (s.CreateCriteria<Party>().SetProjection(Projections.RowCountInt64()).UniqueResultAsync<long>()), Is.EqualTo(0L));
12581259
await (t.CommitAsync());

src/NHibernate.Test/Immutable/EntityWithMutableCollection/AbstractEntityWithOneToManyTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,8 @@ public virtual void OneToManyCollectionOptimisticLockingWithUpdate()
12241224
s = OpenSession();
12251225
t = s.BeginTransaction();
12261226
c = s.CreateCriteria<Contract>().UniqueResult<Contract>();
1227+
s.Delete(c);
1228+
12271229
// If the entity uses a join mapping, DML queries require temp tables.
12281230
if (Dialect.SupportsTemporaryTables)
12291231
s.CreateQuery("delete from Party").ExecuteUpdate();
@@ -1241,7 +1243,6 @@ public virtual void OneToManyCollectionOptimisticLockingWithUpdate()
12411243
s.Delete(newParty);
12421244
}
12431245

1244-
s.Delete(c);
12451246
Assert.That(s.CreateCriteria<Contract>().SetProjection(Projections.RowCountInt64()).UniqueResult<long>(), Is.EqualTo(0L));
12461247
Assert.That(s.CreateCriteria<Party>().SetProjection(Projections.RowCountInt64()).UniqueResult<long>(), Is.EqualTo(0L));
12471248
t.Commit();

0 commit comments

Comments
 (0)