Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7a763be

Browse files
Fix ByCode OneToOne XML serialization (#3613)
1 parent ac2ff3a commit 7a763be

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using NHibernate.Cfg;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH3607
7+
{
8+
/// <summary>
9+
/// By code mapping serialization failure since v5.4.1. Adapted from <see href="https://github.com/craigfowler/NHibernate.XmlConversionBug" />.
10+
/// </summary>
11+
[TestFixture]
12+
public class FixtureByCode : TestCaseMappingByCode
13+
{
14+
protected override HbmMapping GetMappings()
15+
{
16+
var mapper = new ModelMapper();
17+
mapper.AddMappings(new[] { typeof(OrderMapping), typeof(LineItemMapping), typeof(LineItemDataMapping) });
18+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
19+
}
20+
21+
[Test]
22+
public void SerializeMappingToXml()
23+
{
24+
var mapping = GetMappings();
25+
string serialized = "";
26+
Assert.That(() => serialized = mapping.AsString(), Throws.Nothing, "Mapping serialization failure");
27+
var config = new Configuration();
28+
Assert.That(() => config.AddXml(serialized), Throws.Nothing, "Configuration with serialized mapping has failed");
29+
}
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH3607
2+
{
3+
public class LineItem
4+
{
5+
public virtual int Id { get; set; }
6+
7+
public virtual Order ParentOrder { get; set; }
8+
9+
public virtual string ItemName { get; set; }
10+
11+
public virtual decimal Amount { get; set; }
12+
13+
public virtual LineItemData Data { get; set; }
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.NHSpecificTest.GH3607
2+
{
3+
public class LineItemData
4+
{
5+
public virtual LineItem LineItem { get; set; }
6+
7+
public virtual string Data { get; set; }
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using NHibernate.Mapping.ByCode.Conformist;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3607
4+
{
5+
public class LineItemDataMapping : ClassMapping<LineItemData>
6+
{
7+
public LineItemDataMapping()
8+
{
9+
OneToOne(x => x.LineItem, m => m.Constrained(true));
10+
11+
Property(x => x.Data);
12+
}
13+
}
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NHibernate.Mapping.ByCode;
2+
using NHibernate.Mapping.ByCode.Conformist;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3607
5+
{
6+
public class LineItemMapping : ClassMapping<LineItem>
7+
{
8+
public LineItemMapping()
9+
{
10+
Id(x => x.Id, m => m.Generator(new IdentityGeneratorDef()));
11+
12+
Property(x => x.ItemName);
13+
14+
Property(x => x.Amount);
15+
16+
ManyToOne(x => x.ParentOrder);
17+
18+
ManyToOne(x => x.Data);
19+
}
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3607
5+
{
6+
public class Order
7+
{
8+
public virtual int Id { get; set; }
9+
10+
public virtual DateTime CreatedDate { get; set; }
11+
12+
public virtual ISet<LineItem> Items { get; protected set; } = new HashSet<LineItem>();
13+
}
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NHibernate.Mapping.ByCode;
2+
using NHibernate.Mapping.ByCode.Conformist;
3+
4+
namespace NHibernate.Test.NHSpecificTest.GH3607
5+
{
6+
public class OrderMapping : ClassMapping<Order>
7+
{
8+
public OrderMapping()
9+
{
10+
Table("`Order`");
11+
Id(x => x.Id, m => m.Generator(new IdentityGeneratorDef()));
12+
13+
Property(x => x.CreatedDate);
14+
15+
Set(x => x.Items, m =>
16+
{
17+
m.Inverse(true);
18+
m.OptimisticLock(true);
19+
}, a => a.OneToMany());
20+
}
21+
}
22+
}

‎src/NHibernate/Cfg/MappingSchema/HbmOneToOne.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ public string Access
1818
get { return access; }
1919
}
2020

21+
// 6.0 Todo : remove XmlIgnore after removing the setter. See #3607 fix.
22+
[XmlIgnore]
2123
public bool OptimisticLock
2224
{
2325
get => optimisticlock;
26+
// Since v5.4.10
27+
[Obsolete("Providing a setter for OptimisticLock was unintended and will be removed.")]
2428
set => optimisticlock = value;
2529
}
2630

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /