Skip to content

Cease having dynamic composite-id causing swallowed exceptions #1938

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 2 commits into from
Dec 19, 2018
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
66 changes: 66 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/NH3865/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


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<string, object> _compId;

protected override void OnSetUp()
{
_compId = new Dictionary<string, object>
{
["IdPart1"] = 1,
["IdPart2"] = 2
};
var entity = new Dictionary<string, object>
{
["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<string, object>) 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();
}
}
}
}
55 changes: 55 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3865/Fixture.cs
Original file line number Diff line number Diff line change
@@ -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<string, object> _compId;

protected override void OnSetUp()
{
_compId = new Dictionary<string, object>
{
["IdPart1"] = 1,
["IdPart2"] = 2
};
var entity = new Dictionary<string, object>
{
["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<string, object>) 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();
}
}
}
}
19 changes: 19 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3865/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.NH3865">

<class entity-name="MyEntity">
<composite-id name="CompId">
<key-property name="IdPart1" type="Int32">
<column name="Id1"/>
</key-property>
<key-property name="IdPart2" type="Int32">
<column name="Id2"/>
</key-property>
</composite-id>
<property name="Name" type="string"/>
</class>

</hibernate-mapping>

6 changes: 2 additions & 4 deletions src/NHibernate/Mapping/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,15 @@ public System.Type ComponentClass
get
{
// NH Different implementation (we use reflection only when needed)
if (componentClass == null)
if (componentClass == null && !IsDynamic)
{
try
{
componentClass = ReflectHelper.ClassForName(componentClassName);
}
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;
Expand Down