Skip to content

Commit 4460dba

Browse files
committedMay 10, 2021
Change cascade style for DefaultDirtyCheckEventListener to persist on flush
The default cascade for it was SaveUpdate (via base AbstractFlushingEventListener) which triggered insertion of the entities with post-insert style ID generators (eg. identity). Persist on the other hand will make sure that insertion of the entity is delyed until flush is called. Fixes nhibernate#1413
1 parent 07ecb9f commit 4460dba

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed
 

‎src/NHibernate.Test/Async/NHSpecificTest/GH1413/FixtureByCode.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ protected override void OnTearDown()
7474
}
7575
}
7676

77-
[Test]
78-
[KnownBug("#1413")]
79-
public async Task SessionIsDirtyShouldNotTriggerCascadeSavingAsync()
77+
[Theory]
78+
public async Task SessionIsDirtyShouldNotTriggerCascadeSavingAsync(bool beginTransaction)
8079
{
8180
Sfi.Statistics.IsStatisticsEnabled = true;
8281
using (var session = OpenSession())
83-
using (session.BeginTransaction())
82+
using (beginTransaction ? session.BeginTransaction() : null)
8483
{
8584
var parent = await (GetParentAsync(session));
8685
var entityChild = new EntityChild

‎src/NHibernate.Test/NHSpecificTest/GH1413/FixtureByCode.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ protected override void OnTearDown()
6262
}
6363
}
6464

65-
[Test]
66-
[KnownBug("#1413")]
67-
public void SessionIsDirtyShouldNotTriggerCascadeSaving()
65+
[Theory]
66+
public void SessionIsDirtyShouldNotTriggerCascadeSaving(bool beginTransaction)
6867
{
6968
Sfi.Statistics.IsStatisticsEnabled = true;
7069
using (var session = OpenSession())
71-
using (session.BeginTransaction())
70+
using (beginTransaction ? session.BeginTransaction() : null)
7271
{
7372
var parent = GetParent(session);
7473
var entityChild = new EntityChild

‎src/NHibernate/Async/Event/Default/DefaultDirtyCheckEventListener.cs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010

1111
using System;
12+
using NHibernate.Engine;
13+
using NHibernate.Util;
1214

1315
namespace NHibernate.Event.Default
1416
{

‎src/NHibernate/Event/Default/DefaultDirtyCheckEventListener.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using NHibernate.Engine;
3+
using NHibernate.Util;
24

35
namespace NHibernate.Event.Default
46
{
@@ -11,6 +13,10 @@ public partial class DefaultDirtyCheckEventListener : AbstractFlushingEventListe
1113
{
1214
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(DefaultDirtyCheckEventListener));
1315

16+
protected override object Anything => IdentityMap.Instantiate(10);
17+
18+
protected override CascadingAction CascadingAction => CascadingAction.Persist;
19+
1420
public virtual void OnDirtyCheck(DirtyCheckEvent @event)
1521
{
1622
int oldSize = @event.Session.ActionQueue.CollectionRemovalsCount;

0 commit comments

Comments
 (0)