Skip to content

Add missing possible breaking change #1927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
@@ -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
=============================

Expand All @@ -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
Expand Down
67 changes: 65 additions & 2 deletions src/NHibernate.Test/NHSpecificTest/GH1875/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BadlyMappedEntity>(
Expand All @@ -42,7 +50,7 @@ protected HbmMapping GetMappings()
[Test]
public void ShouldThrowSoundErrorForBadlyMappedEntity()
{
var mappings = GetMappings();
var mappings = GetBadMappings();
var cfg = TestConfigurationHelper.GetDefaultConfiguration();
cfg.AddMapping(mappings);

Expand All @@ -59,5 +67,60 @@ public void ShouldThrowSoundErrorForBadlyMappedEntity()
factory?.Dispose();
}
}

protected HbmMapping GetValidMappings()
{
var mapper = new ModelMapper();
mapper.Class<EntityWithReadOnlyPropertiesDuplicatingColumns>(
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();
}
}
}
}