From: <fab...@us...> - 2009-10-14 20:50:39
|
Revision: 4751 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4751&view=rev Author: fabiomaulo Date: 2009-10-14 20:50:22 +0000 (Wed, 14 Oct 2009) Log Message: ----------- Minor (demonstration NH-1025 not an issue implementing Equals and GetHashCode as required for set) Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Fixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Mappings.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Model.cs Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Fixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Fixture.cs 2009-10-14 20:50:22 UTC (rev 4751) @@ -0,0 +1,58 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1025 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void Test() + { + var e = new Entity(); + e.Components.Add(new Component(1, 2, null)); + e.Components.Add(new Component(null, 2, 3)); + e.Components.Add(new Component(1, null, 3)); + + // Save our entity with 3 Components that contain null-valued properties + // null values are required to generate invalid SQL. + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.SaveOrUpdate(e); + t.Commit(); + } + + // Retrieve entity, and add an additional component. Incorrect SQL will include + // 'WHERE ValueA = NULL AND ...' etc. Correct SQL should be 'WHERE ValueA IS NULL AND ...' etc. + // This causes the old component records to not be found, and the new collection gets appended + // to the old collection, resulting in OriginalCollection.Count + ModifiedCollection.Count records. + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var e2 = s.Get<Entity>(e.Id); + e2.Components.Add(new Component(null, null, 3)); + + s.SaveOrUpdate(e2); + t.Commit(); + } + + // NH1025 results in 7 retrieved Components, instead of the expected 4. + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + var e3 =s.Get<Entity>(e.Id); + Assert.AreEqual(4, e3.Components.Count); + } + } + + protected override void OnTearDown() + { + using (var s = OpenSession()) + using (var t = s.BeginTransaction()) + { + s.Delete("from Entity"); + t.Commit(); + } + } + } +} Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Mappings.hbm.xml 2009-10-14 20:50:22 UTC (rev 4751) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1025"> + + <class name="Entity"> + <id name="Id"> + <generator class="native" /> + </id> + + <set name ="Components" table="Components" > + <key column="EntityID" /> + <composite-element class="Component"> + <parent name="Parent"/> + <property name="ValueA" /> + <property name="ValueB" /> + <property name="ValueC" /> + </composite-element> + </set> + </class> +</hibernate-mapping> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Model.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Model.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1025/Model.cs 2009-10-14 20:50:22 UTC (rev 4751) @@ -0,0 +1,79 @@ +using System; +using Iesi.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1025 +{ + public class Entity + { + public Entity() + { + Components = new HashedSet<Component>(); + } + + public virtual int Id { get; set; } + + public virtual ISet<Component> Components { get; set; } + } + + public class Component : IEquatable<Component> + { + public Component() + { + + } + + public Component(int? valueA, int? valueB, int? valueC) + { + ValueA = valueA; + ValueB = valueB; + ValueC = valueC; + } + + public virtual Entity Parent { get; set; } + + public virtual int? ValueA { get; set; } + public virtual int? ValueB { get; set; } + public virtual int? ValueC { get; set; } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != typeof (Component)) + { + return false; + } + return Equals((Component) obj); + } + + public bool Equals(Component other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + if (ReferenceEquals(this, other)) + { + return true; + } + return other.ValueA.Equals(ValueA) && other.ValueB.Equals(ValueB) && other.ValueC.Equals(ValueC); + } + + public override int GetHashCode() + { + unchecked + { + int result = (ValueA.HasValue ? ValueA.Value : 0); + result = (result * 397) ^ (ValueB.HasValue ? ValueB.Value : 0); + result = (result * 397) ^ (ValueC.HasValue ? ValueC.Value : 0); + return result; + } + } + } +} Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-14 20:38:28 UTC (rev 4750) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-14 20:50:22 UTC (rev 4751) @@ -363,6 +363,8 @@ <Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagPartialNameFixture.cs" /> <Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagFixture.cs" /> <Compile Include="NHSpecificTest\ElementsEnums\Something.cs" /> + <Compile Include="NHSpecificTest\NH1025\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1025\Model.cs" /> <Compile Include="NHSpecificTest\NH1905\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1905\Model.cs" /> <Compile Include="NHSpecificTest\NH1908ThreadSafety\Fixture.cs" /> @@ -2000,6 +2002,7 @@ <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1025\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1985\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1990\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |