Skip to content

Commit b0d23ab

Browse files
dpodzyubanRogerKratz
authored andcommitted
Fix More then one save in transaction with one-to-one relations throw exception.
1 parent 4523dfd commit b0d23ab

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using NHibernate.Cfg;
2+
using NHibernate.Envers.Configuration;
3+
using NUnit.Framework;
4+
using SharpTestsEx;
5+
6+
namespace NHibernate.Envers.Tests.Integration.OneToOne.BiDirectional
7+
{
8+
public class BidirectionalSaveTest : TestBase
9+
{
10+
private const int id = 18;
11+
12+
public BidirectionalSaveTest(AuditStrategyForTest strategyType) : base(strategyType)
13+
{
14+
}
15+
16+
protected override void AddToConfiguration(Cfg.Configuration configuration)
17+
{
18+
configuration.SetEnversProperty(ConfigurationKey.GlobalWithModifiedFlag, true);
19+
}
20+
21+
22+
protected override void Initialize()
23+
{
24+
var entity = new BiRefEdEntity { Id = id, Data = "1" };
25+
26+
using (var tx = Session.BeginTransaction())
27+
{
28+
Session.Save(entity);
29+
30+
entity.Data = "2";
31+
Session.Update(entity);
32+
tx.Commit();
33+
}
34+
}
35+
36+
37+
[Test]
38+
public void VerifyRevisionCount()
39+
{
40+
AuditReader().GetRevisions(typeof(BiRefEdEntity), id)
41+
.Should().Have.SameSequenceAs(1);
42+
}
43+
44+
[Test]
45+
public void VerifyHistory()
46+
{
47+
AuditReader().Find<BiRefEdEntity>(id, 1).Data.Should().Be.EqualTo("2");
48+
}
49+
}
50+
}

Src/NHibernate.Envers/Synchronization/Work/AddWorkUnit.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ private IDictionary<string, object> mergeModifiedFlags(IDictionary<string, objec
7777
{
7878
if (propertyData.UsingModifiedFlag)
7979
{
80-
var lhsValue = (bool)lhs[propertyData.ModifiedFlagPropertyName];
81-
if (lhsValue)
80+
if (lhs.TryGetValue(propertyData.ModifiedFlagPropertyName, out var lhsUntypedValue))
8281
{
83-
var rhsValue = (bool) rhs[propertyData.ModifiedFlagPropertyName];
84-
if (!rhsValue)
82+
var lhsValue = (bool)lhsUntypedValue;
83+
if (lhsValue)
8584
{
8685
rhs[propertyData.ModifiedFlagPropertyName] = true;
8786
}

0 commit comments

Comments
 (0)