Skip to content

Commit b2e5396

Browse files
Add missing possible breaking change
Add test for how it should be handled
1 parent 19e13e0 commit b2e5396

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

releasenotes.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Build 5.2.1
2+
=============================
3+
4+
Release notes - NHibernate - Version 5.2.1
5+
6+
As part of releasing 5.2.1, a missing 5.2.0 possible breaking change has been added about duplicated columns
7+
in mapping. See 5.2.0 possible breaking changes.
8+
19
Build 5.2.0
210
=============================
311

@@ -6,6 +14,11 @@ Release notes - NHibernate - Version 5.2.0
614
157 issues were resolved in this release.
715

816
##### Possible Breaking Changes #####
17+
* Entities having many non-readonly properties (including many-to-one) mapped to
18+
the same column will no more silently ignore the trouble till an insert or update
19+
is attempted. They will now cause the session factory built to fail. When
20+
mapping many properties to the same column, all of them excepted at most one
21+
should be mapped with `insert="false" update="false"`.
922
* Mappings mixing column elements and formula elements were taking into account
1023
only the formula elements. They will now take into account all elements.
1124
* Mappings mixing column elements and/or formula elements with a column attribute

src/NHibernate.Test/NHSpecificTest/GH1875/Fixture.cs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ public class BadlyMappedEntity
1212
public virtual long SecondValue { get; set; }
1313
}
1414

15+
public class EntityWithReadOnlyPropertiesDuplicatingColumns
16+
{
17+
public virtual Guid Id { get; set; }
18+
public virtual Guid IdCopy { get; set; }
19+
// Just to "emulate" a pseudo one-to-one while not actually having another entity to map.
20+
public virtual EntityWithReadOnlyPropertiesDuplicatingColumns Self { get; set; }
21+
}
22+
1523
[TestFixture]
1624
public class Fixture
1725
{
18-
protected HbmMapping GetMappings()
26+
protected HbmMapping GetBadMappings()
1927
{
2028
var mapper = new ModelMapper();
2129
mapper.Class<BadlyMappedEntity>(
@@ -42,7 +50,7 @@ protected HbmMapping GetMappings()
4250
[Test]
4351
public void ShouldThrowSoundErrorForBadlyMappedEntity()
4452
{
45-
var mappings = GetMappings();
53+
var mappings = GetBadMappings();
4654
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
4755
cfg.AddMapping(mappings);
4856

@@ -59,5 +67,60 @@ public void ShouldThrowSoundErrorForBadlyMappedEntity()
5967
factory?.Dispose();
6068
}
6169
}
70+
71+
protected HbmMapping GetValidMappings()
72+
{
73+
var mapper = new ModelMapper();
74+
mapper.Class<EntityWithReadOnlyPropertiesDuplicatingColumns>(
75+
ca =>
76+
{
77+
ca.Abstract(true);
78+
ca.Id(
79+
x => x.Id,
80+
map =>
81+
{
82+
map.Column("EntityId");
83+
map.Generator(Generators.GuidComb);
84+
});
85+
ca.ManyToOne(
86+
x => x.Self,
87+
map =>
88+
{
89+
map.Column("EntityId");
90+
map.Update(false);
91+
map.Insert(false);
92+
});
93+
ca.Property(
94+
x => x.IdCopy,
95+
map =>
96+
{
97+
map.Column("EntityId");
98+
map.Update(false);
99+
map.Insert(false);
100+
});
101+
});
102+
103+
return mapper.CompileMappingFor(new[] { typeof(BadlyMappedEntity) });
104+
}
105+
106+
[Test]
107+
public void ShouldAcceptReadOnlyPropertiesDuplicatingAColumn()
108+
{
109+
var mappings = GetValidMappings();
110+
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
111+
cfg.AddMapping(mappings);
112+
113+
ISessionFactory factory = null;
114+
try
115+
{
116+
Assert.That(
117+
() => factory = cfg.BuildSessionFactory(),
118+
Throws.Nothing);
119+
}
120+
finally
121+
{
122+
factory?.Dispose();
123+
}
124+
}
62125
}
63126
}

0 commit comments

Comments
 (0)