From 253b47102a83cfbdf654fd217b26fe3249003c2a Mon Sep 17 00:00:00 2001 From: Rafael Lillo Date: Wed, 10 Apr 2019 21:22:16 +0100 Subject: [PATCH 1/4] add test --- .../NHSpecificTest/NH2714/Fixture.cs | 66 +++++++++++++++++++ .../NHSpecificTest/NH2714/Information.cs | 12 ++++ .../NHSpecificTest/NH2714/Item.cs | 9 +++ .../NHSpecificTest/NH2714/Mappings.hbm.xml | 27 ++++++++ 4 files changed, 114 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/NH2714/Information.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/NH2714/Item.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml diff --git a/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs new file mode 100644 index 00000000000..19947afe47c --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs @@ -0,0 +1,66 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2714 +{ + [TestFixture] + public class Fixture : BugTestCase + { + private const int ExtraId = 500; + + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + { + s.Delete($"from {nameof(Item)}"); + s.Flush(); + s.Delete($"from {nameof(Information)}"); + s.Flush(); + } + } + + [Test] + public void PropertyRefUsesOtherColumns() + { + var information = new Information {Name = "First", ExtraId = ExtraId}; + + var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; + + using (ISession session = OpenSession()) + { + session.Save(information); + session.Save(item); + session.Flush(); + } + + using (ISession session = OpenSession()) + { + var otherInformation = session.Get(information.Id); + + Assert.That(otherInformation.Items.Count, Is.EqualTo(1)); + } + } + + [Test] + public void ChildKeyPropertiesOfParentAreRetrieved() + { + var information = new Information {Name = "First", ExtraId = ExtraId}; + + var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; + + using (ISession session = OpenSession()) + { + session.Save(information); + session.Save(item); + session.Flush(); + } + + using (ISession session = OpenSession()) + { + var otherInformation = session.Get(information.Id); + + Assert.That(otherInformation.Name, Is.EqualTo(information.Name)); + Assert.That(otherInformation.ExtraId, Is.EqualTo(information.ExtraId)); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH2714/Information.cs b/src/NHibernate.Test/NHSpecificTest/NH2714/Information.cs new file mode 100644 index 00000000000..fbff5a49650 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH2714/Information.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2714 +{ + public class Information + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual int ExtraId { get; set; } + public virtual ISet Items { get; set; } = new HashSet(); + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH2714/Item.cs b/src/NHibernate.Test/NHSpecificTest/NH2714/Item.cs new file mode 100644 index 00000000000..db4128a4276 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH2714/Item.cs @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH2714 +{ + public class Item + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual int ExtraId { get; set; } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml new file mode 100644 index 00000000000..c3a2677d5b2 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 855e16afa3c90a72f45ff715dbaab3c75afe023d Mon Sep 17 00:00:00 2001 From: Rafael Lillo Date: Wed, 24 Apr 2019 18:48:48 +0100 Subject: [PATCH 2/4] improve test --- src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs | 1 - .../NHSpecificTest/NH2714/Mappings.hbm.xml | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs index 19947afe47c..3f8123d48c3 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH2714/Fixture.cs @@ -35,7 +35,6 @@ public void PropertyRefUsesOtherColumns() using (ISession session = OpenSession()) { var otherInformation = session.Get(information.Id); - Assert.That(otherInformation.Items.Count, Is.EqualTo(1)); } } diff --git a/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml index c3a2677d5b2..eb4f07ee80d 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml +++ b/src/NHibernate.Test/NHSpecificTest/NH2714/Mappings.hbm.xml @@ -5,13 +5,13 @@ - - + + - - + + @@ -21,7 +21,7 @@ - + \ No newline at end of file From 21c998c1cb38af5f6213b7553e919b515da3eac0 Mon Sep 17 00:00:00 2001 From: Alexander Zaytsev Date: Mon, 29 Apr 2019 23:08:20 +1200 Subject: [PATCH 3/4] Proper fix --- src/NHibernate/Type/EmbeddedComponentType.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/NHibernate/Type/EmbeddedComponentType.cs b/src/NHibernate/Type/EmbeddedComponentType.cs index 0964217419d..5fe81b36a76 100644 --- a/src/NHibernate/Type/EmbeddedComponentType.cs +++ b/src/NHibernate/Type/EmbeddedComponentType.cs @@ -19,9 +19,12 @@ public override bool IsEmbedded public override object Instantiate(object parent, ISessionImplementor session) { - bool useParent= false; - // NH Different implementation : since we are not sure about why H3.2 use the "parent" - //useParent = parent != null && base.ReturnedClass.IsInstanceOfType(parent); + var useParent = + parent != null && + //TODO: Yuck! This is not quite good enough, it's a quick + //hack around the problem of having a to-one association + //that refers to an embedded component: + ReturnedClass.IsInstanceOfType(parent); return useParent ? parent : base.Instantiate(parent, session); } From ee2c00a0f17365d34736c3c5dc6d528ff4bc4ff8 Mon Sep 17 00:00:00 2001 From: Alexander Zaytsev Date: Mon, 29 Apr 2019 23:30:51 +1200 Subject: [PATCH 4/4] Generate async --- .../Async/NHSpecificTest/NH2714/Fixture.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/NHibernate.Test/Async/NHSpecificTest/NH2714/Fixture.cs diff --git a/src/NHibernate.Test/Async/NHSpecificTest/NH2714/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/NH2714/Fixture.cs new file mode 100644 index 00000000000..3f36005ebe0 --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/NH2714/Fixture.cs @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2714 +{ + using System.Threading.Tasks; + [TestFixture] + public class FixtureAsync : BugTestCase + { + private const int ExtraId = 500; + + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + { + s.Delete($"from {nameof(Item)}"); + s.Flush(); + s.Delete($"from {nameof(Information)}"); + s.Flush(); + } + } + + [Test] + public async Task PropertyRefUsesOtherColumnsAsync() + { + var information = new Information {Name = "First", ExtraId = ExtraId}; + + var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; + + using (ISession session = OpenSession()) + { + await (session.SaveAsync(information)); + await (session.SaveAsync(item)); + await (session.FlushAsync()); + } + + using (ISession session = OpenSession()) + { + var otherInformation = await (session.GetAsync(information.Id)); + Assert.That(otherInformation.Items.Count, Is.EqualTo(1)); + } + } + + [Test] + public async Task ChildKeyPropertiesOfParentAreRetrievedAsync() + { + var information = new Information {Name = "First", ExtraId = ExtraId}; + + var item = new Item {Id = 1, Name = information.Name, ExtraId = information.ExtraId}; + + using (ISession session = OpenSession()) + { + await (session.SaveAsync(information)); + await (session.SaveAsync(item)); + await (session.FlushAsync()); + } + + using (ISession session = OpenSession()) + { + var otherInformation = await (session.GetAsync(information.Id)); + + Assert.That(otherInformation.Name, Is.EqualTo(information.Name)); + Assert.That(otherInformation.ExtraId, Is.EqualTo(information.ExtraId)); + } + } + } +}