Skip to content

Commit 8590368

Browse files
ogvolkovhazzik
authored andcommitted
NH-3757 - Allow dynamic entity mapped with entity-name to have a component of a fixed class
1 parent 90f5234 commit 8590368

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Test.NHSpecificTest.NH3757
5+
{
6+
[TestFixture]
7+
public class Fixture : BugTestCase
8+
{
9+
protected override void OnTearDown()
10+
{
11+
using (ISession s = OpenSession())
12+
{
13+
using (ITransaction tx = s.BeginTransaction())
14+
{
15+
s.CreateSQLQuery("delete from EntityName").ExecuteUpdate();
16+
tx.Commit();
17+
}
18+
}
19+
}
20+
21+
[Test]
22+
public void ShouldBePossibleToHaveComponentInEntityNameMappedEntity()
23+
{
24+
using (ISession session = OpenSession())
25+
using (ITransaction transaction = session.BeginTransaction())
26+
{
27+
var e1 = new Dictionary<string, object>();
28+
e1["Money"] = new Money { Amount = 100m, Currency = "USD" };
29+
session.Save("EntityName", e1);
30+
31+
session.Flush();
32+
transaction.Commit();
33+
}
34+
}
35+
}
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3757">
3+
4+
<class entity-name="EntityName">
5+
<id name="Id" type="Int32" generator="native" />
6+
<component name="Money" class="Money">
7+
<property name="Amount" type="decimal"/>
8+
<property name="Currency" type="string"/>
9+
</component>
10+
</class>
11+
12+
</hibernate-mapping>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3757
2+
{
3+
public class Money
4+
{
5+
public virtual decimal Amount { get; set; }
6+
7+
public virtual string Currency { get; set; }
8+
}
9+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@
13211321
<Compile Include="NHSpecificTest\NH3641\TestFixture.cs" />
13221322
<Compile Include="NHSpecificTest\NH3800\Domain.cs" />
13231323
<Compile Include="NHSpecificTest\NH3800\Fixture.cs" />
1324+
<Compile Include="NHSpecificTest\NH3757\Fixture.cs" />
1325+
<Compile Include="NHSpecificTest\NH3757\Money.cs" />
13241326
<Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" />
13251327
<Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" />
13261328
<Compile Include="NHSpecificTest\Properties\Model.cs" />
@@ -3221,6 +3223,7 @@
32213223
<EmbeddedResource Include="NHSpecificTest\NH3800\Mappings.hbm.xml">
32223224
<SubType>Designer</SubType>
32233225
</EmbeddedResource>
3226+
<EmbeddedResource Include="NHSpecificTest\NH3757\Mappings.hbm.xml" />
32243227
<EmbeddedResource Include="LazyComponentTest\Person.hbm.xml" />
32253228
<EmbeddedResource Include="NHSpecificTest\NH3372\Mappings.hbm.xml" />
32263229
<EmbeddedResource Include="NHSpecificTest\NH3567\Mappings.hbm.xml" />

src/NHibernate/Tuple/Component/ComponentEntityModeToTuplizerMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ComponentEntityModeToTuplizerMapping(Mapping.Component component)
4646
userSuppliedTuplizerImpls.TryGetValue(EntityMode.Poco, out tempObject2);
4747
userSuppliedTuplizerImpls.Remove(EntityMode.Poco);
4848
tuplizerImpl = tempObject2;
49-
if (owner.HasPocoRepresentation && component.HasPocoRepresentation)
49+
if (component.HasPocoRepresentation)
5050
{
5151
if (tuplizerImpl == null)
5252
{

0 commit comments

Comments
 (0)