From 43916229121fe575cfb27cdd5421f2bed17ba8cf Mon Sep 17 00:00:00 2001 From: Roger Kratz Date: Mon, 17 Dec 2018 13:39:35 +0100 Subject: [PATCH 1/2] Example code for NH-3865 --- .../NHSpecificTest/NH3865/Fixture.cs | 55 +++++++++++++++++++ .../NHSpecificTest/NH3865/Mappings.hbm.xml | 19 +++++++ 2 files changed, 74 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml diff --git a/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs new file mode 100644 index 00000000000..7e7144b03c0 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH3865 +{ + [TestFixture] + public class Fixture : BugTestCase + { + private const string entityName = "MyEntity"; + + private IDictionary compId; + + protected override void OnSetUp() + { + compId = new Dictionary + { + ["IdPart1"] = 1, + ["IdPart2"] = 2 + }; + var entity = new Dictionary + { + ["CompId"] = compId, + ["Name"] = "some name" + }; + + using(var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + s.Save(entityName, entity); + tx.Commit(); + } + } + + [Test] + public void ReadDynamicEntityWithCompositeId() + { + using(var s = OpenSession()) + using (s.BeginTransaction()) + { + var entity = (IDictionary)s.Get(entityName, compId); + Assert.That(entity["Name"], Is.EqualTo("some name")); + } + } + + protected override void OnTearDown() + { + using(var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + s.Delete($"from MyEntity {entityName}"); + tx.Commit(); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml new file mode 100644 index 00000000000..f11171916fa --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + From dbea7bb6d52ba1329c59b62edf4a6bf72d06af59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Tue, 18 Dec 2018 17:21:35 +0100 Subject: [PATCH 2/2] Remove an undue handling by exception And reformat test and generate async code for test --- .../Async/NHSpecificTest/NH3865/Fixture.cs | 66 +++++++++++++++++++ .../NHSpecificTest/NH3865/Fixture.cs | 22 +++---- .../NHSpecificTest/NH3865/Mappings.hbm.xml | 12 ++-- src/NHibernate/Mapping/Component.cs | 6 +- 4 files changed, 85 insertions(+), 21 deletions(-) create mode 100644 src/NHibernate.Test/Async/NHSpecificTest/NH3865/Fixture.cs diff --git a/src/NHibernate.Test/Async/NHSpecificTest/NH3865/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/NH3865/Fixture.cs new file mode 100644 index 00000000000..2b166c2255e --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/NH3865/Fixture.cs @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH3865 +{ + using System.Threading.Tasks; + [TestFixture] + public class FixtureAsync : BugTestCase + { + private const string _entityName = "MyEntity"; + + private IDictionary _compId; + + protected override void OnSetUp() + { + _compId = new Dictionary + { + ["IdPart1"] = 1, + ["IdPart2"] = 2 + }; + var entity = new Dictionary + { + ["CompId"] = _compId, + ["Name"] = "some name" + }; + + using (var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + s.Save(_entityName, entity); + tx.Commit(); + } + } + + [Test] + public async Task ReadDynamicEntityWithCompositeIdAsync() + { + using (var s = OpenSession()) + using (s.BeginTransaction()) + { + var entity = (IDictionary) await (s.GetAsync(_entityName, _compId)); + Assert.That(entity["Name"], Is.EqualTo("some name")); + } + } + + protected override void OnTearDown() + { + using (var s = OpenSession()) + using (var tx = s.BeginTransaction()) + { + s.Delete($"from MyEntity {_entityName}"); + tx.Commit(); + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs index 7e7144b03c0..b83c470e596 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs @@ -6,27 +6,27 @@ namespace NHibernate.Test.NHSpecificTest.NH3865 [TestFixture] public class Fixture : BugTestCase { - private const string entityName = "MyEntity"; + private const string _entityName = "MyEntity"; + + private IDictionary _compId; - private IDictionary compId; - protected override void OnSetUp() { - compId = new Dictionary + _compId = new Dictionary { ["IdPart1"] = 1, ["IdPart2"] = 2 }; var entity = new Dictionary { - ["CompId"] = compId, + ["CompId"] = _compId, ["Name"] = "some name" }; - using(var s = OpenSession()) + using (var s = OpenSession()) using (var tx = s.BeginTransaction()) { - s.Save(entityName, entity); + s.Save(_entityName, entity); tx.Commit(); } } @@ -34,20 +34,20 @@ protected override void OnSetUp() [Test] public void ReadDynamicEntityWithCompositeId() { - using(var s = OpenSession()) + using (var s = OpenSession()) using (s.BeginTransaction()) { - var entity = (IDictionary)s.Get(entityName, compId); + var entity = (IDictionary) s.Get(_entityName, _compId); Assert.That(entity["Name"], Is.EqualTo("some name")); } } protected override void OnTearDown() { - using(var s = OpenSession()) + using (var s = OpenSession()) using (var tx = s.BeginTransaction()) { - s.Delete($"from MyEntity {entityName}"); + s.Delete($"from MyEntity {_entityName}"); tx.Commit(); } } diff --git a/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml index f11171916fa..bb799ea5611 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml +++ b/src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml @@ -1,19 +1,19 @@  - + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH3865"> + - + - + - + diff --git a/src/NHibernate/Mapping/Component.cs b/src/NHibernate/Mapping/Component.cs index 3a4793d6458..9febe1a6845 100644 --- a/src/NHibernate/Mapping/Component.cs +++ b/src/NHibernate/Mapping/Component.cs @@ -133,7 +133,7 @@ public System.Type ComponentClass get { // NH Different implementation (we use reflection only when needed) - if (componentClass == null) + if (componentClass == null && !IsDynamic) { try { @@ -141,9 +141,7 @@ public System.Type ComponentClass } catch (Exception cnfe) { - if (!IsDynamic) // TODO remove this if leave the Exception - throw new MappingException("component class not found: " + componentClassName, cnfe); - return null; + throw new MappingException("component class not found: " + componentClassName, cnfe); } } return componentClass;