diff --git a/releasenotes.txt b/releasenotes.txt index 1e40afd9a33..cd193256250 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,3 +1,11 @@ +Build 5.2.1 +============================= + +Release notes - NHibernate - Version 5.2.1 + +As part of releasing 5.2.1, a missing 5.2.0 possible breaking change has been added about duplicated columns +in mapping. See 5.2.0 possible breaking changes. + Build 5.2.0 ============================= @@ -6,6 +14,11 @@ Release notes - NHibernate - Version 5.2.0 157 issues were resolved in this release. ##### Possible Breaking Changes ##### + * Entities having many non-readonly properties (including many-to-one) mapped to + the same column will no more silently ignore the trouble till an insert or update + is attempted. They will now cause the session factory built to fail. When + mapping many properties to the same column, all of them excepted at most one + should be mapped with `insert="false" update="false"`. * Mappings mixing column elements and formula elements were taking into account only the formula elements. They will now take into account all elements. * Mappings mixing column elements and/or formula elements with a column attribute diff --git a/src/NHibernate.Test/NHSpecificTest/GH1875/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/GH1875/Fixture.cs index cc5d8d282e5..d2e4c93ec22 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH1875/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH1875/Fixture.cs @@ -12,10 +12,18 @@ public class BadlyMappedEntity public virtual long SecondValue { get; set; } } + public class EntityWithReadOnlyPropertiesDuplicatingColumns + { + public virtual Guid Id { get; set; } + public virtual Guid IdCopy { get; set; } + // Just to "emulate" a pseudo one-to-one while not actually having another entity to map. + public virtual EntityWithReadOnlyPropertiesDuplicatingColumns Self { get; set; } + } + [TestFixture] public class Fixture { - protected HbmMapping GetMappings() + protected HbmMapping GetBadMappings() { var mapper = new ModelMapper(); mapper.Class( @@ -42,7 +50,7 @@ protected HbmMapping GetMappings() [Test] public void ShouldThrowSoundErrorForBadlyMappedEntity() { - var mappings = GetMappings(); + var mappings = GetBadMappings(); var cfg = TestConfigurationHelper.GetDefaultConfiguration(); cfg.AddMapping(mappings); @@ -59,5 +67,60 @@ public void ShouldThrowSoundErrorForBadlyMappedEntity() factory?.Dispose(); } } + + protected HbmMapping GetValidMappings() + { + var mapper = new ModelMapper(); + mapper.Class( + ca => + { + ca.Abstract(true); + ca.Id( + x => x.Id, + map => + { + map.Column("EntityId"); + map.Generator(Generators.GuidComb); + }); + ca.ManyToOne( + x => x.Self, + map => + { + map.Column("EntityId"); + map.Update(false); + map.Insert(false); + }); + ca.Property( + x => x.IdCopy, + map => + { + map.Column("EntityId"); + map.Update(false); + map.Insert(false); + }); + }); + + return mapper.CompileMappingFor(new[] { typeof(BadlyMappedEntity) }); + } + + [Test] + public void ShouldAcceptReadOnlyPropertiesDuplicatingAColumn() + { + var mappings = GetValidMappings(); + var cfg = TestConfigurationHelper.GetDefaultConfiguration(); + cfg.AddMapping(mappings); + + ISessionFactory factory = null; + try + { + Assert.That( + () => factory = cfg.BuildSessionFactory(), + Throws.Nothing); + } + finally + { + factory?.Dispose(); + } + } } }