|
From: <ric...@us...> - 2009-09-27 10:07:02
|
Revision: 4730
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4730&view=rev
Author: ricbrown
Date: 2009-09-27 10:06:52 +0000 (Sun, 27 Sep 2009)
Log Message:
-----------
Merge r4729 (Fix NH-1959, add/remove from IdBag causing KeyNotFoundException)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs 2009-09-27 10:06:11 UTC (rev 4729)
+++ trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs 2009-09-27 10:06:52 UTC (rev 4730)
@@ -290,6 +290,9 @@
protected void BeforeRemove(int index)
{
+ if (!identifiers.ContainsKey(index))
+ return; // index not previously persisted, nothing to do
+
// Move the identifier being removed to the end of the list (i.e. it isn't actually removed).
object removedId = identifiers[index];
int last = values.Count - 1;
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: bugtraq:logregex
+ NH-\d+
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs 2009-09-27 10:06:52 UTC (rev 4730)
@@ -0,0 +1,74 @@
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1959
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+
+ protected override void OnTearDown()
+ {
+ using (ISession s = OpenSession())
+ using(ITransaction tx = s.BeginTransaction())
+ {
+ s.Delete("from ClassB");
+ s.Delete("from ClassA");
+ tx.Commit();
+ }
+ }
+
+ [Test]
+ public void StartWithEmptyDoAddAndRemove()
+ {
+ ClassB b = new ClassB();
+ ClassA a = new ClassA();
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Save(a);
+ s.Save(b);
+ tx.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ ClassA loadedA = s.Get<ClassA>(a.Id);
+ ClassB loadedB = s.Get<ClassB>(b.Id);
+ loadedA.TheBag.Add(loadedB);
+ loadedA.TheBag.Remove(loadedB);
+ tx.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ Assert.AreEqual(0, s.Get<ClassA>(a.Id).TheBag.Count);
+ }
+
+ [Test]
+ public void StartWithEmptyDoAddAndRemoveAt()
+ {
+ ClassB b = new ClassB();
+ ClassA a = new ClassA();
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Save(a);
+ s.Save(b);
+ tx.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ ClassA loadedA = s.Get<ClassA>(a.Id);
+ ClassB loadedB = s.Get<ClassB>(b.Id);
+ loadedA.TheBag.Add(loadedB);
+ loadedA.TheBag.RemoveAt(0);
+ tx.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ Assert.AreEqual(0, s.Get<ClassA>(a.Id).TheBag.Count);
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml 2009-09-27 10:06:52 UTC (rev 4730)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1959"
+ assembly="NHibernate.Test">
+
+ <class name="ClassA">
+ <id name="Id">
+ <generator class="guid.comb"/>
+ </id>
+ <idbag name="TheBag">
+ <collection-id column="collection_id" type="guid">
+ <generator class="guid.comb"/>
+ </collection-id>
+ <key>
+ <column name="classA" not-null="true" />
+ </key>
+ <many-to-many class="ClassB">
+ <column name="classB" not-null="true" />
+ </many-to-many>
+ </idbag>
+ </class>
+
+ <class name="ClassB">
+ <id name="Id">
+ <generator class="guid.comb"/>
+ </id>
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs 2009-09-27 10:06:52 UTC (rev 4730)
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH1959
+{
+ public class ClassA
+ {
+ public virtual Guid Id { get; set; }
+ public virtual IList<ClassB> TheBag { get; set; }
+
+ public ClassA()
+ {
+ TheBag = new List<ClassB>();
+ }
+ }
+
+ public class ClassB
+ {
+ public virtual Guid Id { get; set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-27 10:06:11 UTC (rev 4729)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-27 10:06:52 UTC (rev 4730)
@@ -608,6 +608,8 @@
<Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" />
<Compile Include="NHSpecificTest\NH1948\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1948\Model.cs" />
+ <Compile Include="NHSpecificTest\NH1959\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1959\Model.cs" />
<Compile Include="NHSpecificTest\NH1963\CacheableQueryOnByteArray.cs" />
<Compile Include="NHSpecificTest\NH1963\DomainClass.cs" />
<Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" />
@@ -2027,6 +2029,7 @@
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1963\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|