From: <fab...@us...> - 2010-10-01 11:55:50
|
Revision: 5230 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5230&view=rev Author: fabiomaulo Date: 2010-10-01 11:55:44 +0000 (Fri, 01 Oct 2010) Log Message: ----------- Fix NH-2355 (by Roger Kratz) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2010-09-30 16:27:15 UTC (rev 5229) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2010-10-01 11:55:44 UTC (rev 5230) @@ -19,7 +19,7 @@ compositeId = new Component(rootClass); compositeId.IsKey = true; - + rootClass.Identifier = compositeId; if (idSchema.name == null) @@ -41,7 +41,16 @@ compositeId.Table.SetIdentifierValue(compositeId); compositeId.NullValue = idSchema.unsavedvalue.ToNullValue(); - System.Type compIdClass = compositeId.ComponentClass; + if (!compositeId.IsDynamic) + { + CheckEqualsAndGetHashCodeOverride(); + } + // Serializability check not ported + } + + private void CheckEqualsAndGetHashCodeOverride() + { + var compIdClass = compositeId.ComponentClass; if (!ReflectHelper.OverridesEquals(compIdClass)) { throw new MappingException("composite-id class must override Equals(): " + compIdClass.FullName); @@ -51,7 +60,6 @@ { throw new MappingException("composite-id class must override GetHashCode(): " + compIdClass.FullName); } - // Serializability check not ported } private void BindComponent(System.Type reflectedClass, string path, HbmCompositeId idSchema) @@ -70,8 +78,16 @@ else { // an "embedded" component (ids only) - compositeId.ComponentClass = compositeId.Owner.MappedClass; - compositeId.IsEmbedded = true; + if (compositeId.Owner.HasPocoRepresentation) + { + compositeId.ComponentClass = compositeId.Owner.MappedClass; + compositeId.IsEmbedded = true; + } + else + { + // if not - treat compositeid as a dynamic-component + compositeId.IsDynamic = true; + } } foreach (object item in idSchema.Items ?? new object[0]) Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Fixture.cs 2010-10-01 11:55:44 UTC (rev 5230) @@ -0,0 +1,48 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.EntityNameAndCompositeId +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + s.CreateSQLQuery("delete from Person").ExecuteUpdate(); + tx.Commit(); + } + } + } + + [Test] + public void CanPersistAndRead() + { + object id; + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + id = s.Save("Person", new Dictionary<string, object> + { + {"OuterId", new Dictionary<string, int> {{"InnerId", 1}}}, + {"Data", "hello"} + }); + tx.Commit(); + } + } + using (ISession s = OpenSession()) + { + using (s.BeginTransaction()) + { + var p = (IDictionary) s.Get("Person", id); + Assert.AreEqual("hello", p["Data"]); + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityNameAndCompositeId/Mappings.hbm.xml 2010-10-01 11:55:44 UTC (rev 5230) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.EntityNameAndCompositeId" + assembly="NHibernate.Test"> + <class entity-name="Person"> + <composite-id name="OuterId"> + <key-property name="InnerId" type="Int32" /> + </composite-id> + <property name="Data" type="string"/> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-09-30 16:27:15 UTC (rev 5229) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-01 11:55:44 UTC (rev 5230) @@ -453,6 +453,7 @@ <Compile Include="Linq\ReadonlyTestCase.cs" /> <Compile Include="Logging\Log4NetLoggerTest.cs" /> <Compile Include="Logging\LoggerProviderTest.cs" /> + <Compile Include="NHSpecificTest\EntityNameAndCompositeId\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1136\Address.cs" /> <Compile Include="NHSpecificTest\NH1136\FeeMatrixType.cs" /> <Compile Include="NHSpecificTest\NH1136\Fixture.cs" /> @@ -2317,6 +2318,7 @@ <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\EntityNameAndCompositeId\Mappings.hbm.xml" /> <EmbeddedResource Include="PolymorphicGetAndLoad\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2331\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2324\Mappings.hbm.xml" /> @@ -2661,7 +2663,6 @@ <EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" /> </ItemGroup> <ItemGroup> - <Folder Include="NHSpecificTest\NH1869" /> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |