Skip to content

Commit

Permalink
Fix ByCode OneToOne XML serialization
Browse files Browse the repository at this point in the history
fix #3607
  • Loading branch information
fredericDelaporte committed Sep 29, 2024
1 parent ac2ff3a commit ece6b79
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Linq;
using NHibernate.Cfg;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3607
{
/// <summary>
/// By code mapping serialization failure since v5.4.1. Adapted from <see href="https://github.com/craigfowler/NHibernate.XmlConversionBug" />.
/// </summary>
[TestFixture]
public class FixtureByCode : TestCaseMappingByCode
{
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.AddMappings([typeof(OrderMapping), typeof(LineItemMapping), typeof(LineItemDataMapping)]);

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SQLite

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SQLite

; expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SQLite

} expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SQLite

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Firebird

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Firebird

; expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Firebird

} expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Firebird

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

; expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

} expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

; expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

} expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / MySQL

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / MySQL

; expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / MySQL

} expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / MySQL

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Oracle

) expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Oracle

; expected

Check failure on line 18 in src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs

View workflow job for this annotation

GitHub Actions / Oracle

} expected
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

[Test]
public void SerializeMappingToXml()
{
var mapping = GetMappings();
string serialized = "";
Assert.That(() => serialized = mapping.AsString(), Throws.Nothing, "Mapping serialization failure");
var config = new Configuration();
Assert.That(() => config.AddXml(serialized), Throws.Nothing, "Configuration with serialized mapping has failed");
}
}
}
14 changes: 14 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NHibernate.Test.NHSpecificTest.GH3607;

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs

View workflow job for this annotation

GitHub Actions / SQLite

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs

View workflow job for this annotation

GitHub Actions / Firebird

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs

View workflow job for this annotation

GitHub Actions / MySQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItem.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

public class LineItem
{
public virtual int Id { get; set; }

public virtual Order ParentOrder { get; set; }

public virtual string ItemName { get; set; }

public virtual decimal Amount { get; set; }

public virtual LineItemData Data { get; set; }
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace NHibernate.Test.NHSpecificTest.GH3607;

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs

View workflow job for this annotation

GitHub Actions / SQLite

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs

View workflow job for this annotation

GitHub Actions / Firebird

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs

View workflow job for this annotation

GitHub Actions / MySQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 1 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemData.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

public class LineItemData
{
public virtual LineItem LineItem { get; set; }

public virtual string Data { get; set; }
}
13 changes: 13 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using NHibernate.Mapping.ByCode.Conformist;

namespace NHibernate.Test.NHSpecificTest.GH3607;

Check failure on line 3 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs

View workflow job for this annotation

GitHub Actions / SQLite

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 3 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs

View workflow job for this annotation

GitHub Actions / Firebird

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 3 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 3 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 3 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs

View workflow job for this annotation

GitHub Actions / MySQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 3 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

public class LineItemDataMapping : ClassMapping<LineItemData>
{
public LineItemDataMapping()
{
OneToOne(x => x.LineItem, m => m.Constrained(true));

Property(x => x.Data);
}
}
20 changes: 20 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace NHibernate.Test.NHSpecificTest.GH3607;

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / SQLite

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / Firebird

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / MySQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

public class LineItemMapping : ClassMapping<LineItem>
{
public LineItemMapping()
{
Id(x => x.Id, m => m.Generator(new IdentityGeneratorDef()));

Property(x => x.ItemName);

Property(x => x.Amount);

ManyToOne(x => x.ParentOrder);

ManyToOne(x => x.Data);
}
}
13 changes: 13 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH3607;

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs

View workflow job for this annotation

GitHub Actions / SQLite

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs

View workflow job for this annotation

GitHub Actions / Firebird

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs

View workflow job for this annotation

GitHub Actions / MySQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/Order.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

public class Order
{
public virtual int Id { get; set; }

public virtual DateTime CreatedDate { get; set; }

public virtual ISet<LineItem> Items { get; protected set; } = new HashSet<LineItem>();
}
21 changes: 21 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace NHibernate.Test.NHSpecificTest.GH3607;

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs

View workflow job for this annotation

GitHub Actions / SQLite

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs

View workflow job for this annotation

GitHub Actions / Firebird

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs

View workflow job for this annotation

GitHub Actions / PostgreSQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs

View workflow job for this annotation

GitHub Actions / SqlServer2008

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs

View workflow job for this annotation

GitHub Actions / MySQL

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

Check failure on line 4 in src/NHibernate.Test/NHSpecificTest/GH3607/OrderMapping.cs

View workflow job for this annotation

GitHub Actions / Oracle

Feature 'file-scoped namespace' is not available in C# 9.0. Please use language version 10.0 or greater.

public class OrderMapping : ClassMapping<Order>
{
public OrderMapping()
{
Table("`Order`");
Id(x => x.Id, m => m.Generator(new IdentityGeneratorDef()));

Property(x => x.CreatedDate);

Set(x => x.Items, m =>
{
m.Inverse(true);
m.OptimisticLock(true);
}, a => a.OneToMany());
}
}
4 changes: 4 additions & 0 deletions src/NHibernate/Cfg/MappingSchema/HbmOneToOne.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ public string Access
get { return access; }
}

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

Expand Down

0 comments on commit ece6b79

Please sign in to comment.