|
From: <aye...@us...> - 2010-01-13 15:56:50
|
Revision: 4917
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4917&view=rev
Author: ayenderahien
Date: 2010-01-13 15:56:35 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
Fixing NH-2065 - better error message on reassociation of dirty collection
Fixing NH-2064 - changed exception for filters definition without usage to lor.Error
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/Event/Default/OnLockVisitor.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-10 19:01:42 UTC (rev 4916)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-13 15:56:35 UTC (rev 4917)
@@ -965,8 +965,7 @@
// if you are going to remove this exception at least add a log.Error
// because the usage of filter-def, outside its scope, may cause unexpected behaviour
// during queries.
- throw new MappingException("filter-def for filter named '" + filterName
- + "' was never used to filter classes nor collections.");
+ log.ErrorFormat("filter-def for filter named '{0}' was never used to filter classes nor collections.\r\nThis may result in unexpected behavior during queries", filterName);
}
}
}
Modified: trunk/nhibernate/src/NHibernate/Event/Default/OnLockVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Event/Default/OnLockVisitor.cs 2010-01-10 19:01:42 UTC (rev 4916)
+++ trunk/nhibernate/src/NHibernate/Event/Default/OnLockVisitor.cs 2010-01-13 15:56:35 UTC (rev 4917)
@@ -36,14 +36,14 @@
// a "detached" collection that originally belonged to the same entity
if (persistentCollection.IsDirty)
{
- throw new HibernateException("reassociated object has dirty collection");
+ throw new HibernateException("reassociated object has dirty collection: " + persistentCollection.Role);
}
ReattachCollection(persistentCollection, type);
}
else
{
// a "detached" collection that belonged to a different entity
- throw new HibernateException("reassociated object has dirty collection reference");
+ throw new HibernateException("reassociated object has dirty collection reference: " + persistentCollection.Role);
}
}
else
@@ -51,7 +51,7 @@
// a collection loaded in the current session
// can not possibly be the collection belonging
// to the entity passed to update()
- throw new HibernateException("reassociated object has dirty collection reference");
+ throw new HibernateException("reassociated object has dirty collection reference: " + persistentCollection.Role);
}
}
else
Modified: trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs 2010-01-10 19:01:42 UTC (rev 4916)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs 2010-01-13 15:56:35 UTC (rev 4917)
@@ -1,6 +1,11 @@
+using System;
using System.Collections.Generic;
+using log4net;
+using log4net.Appender;
+using log4net.Config;
using NHibernate.Cfg;
using NUnit.Framework;
+using System.Linq;
namespace NHibernate.Test.FilterTest
{
@@ -236,9 +241,20 @@
var cfg = GetConfiguration();
cfg.AddXmlString(filterDef);
- var e = Assert.Throws<MappingException>(() => cfg.BuildSessionFactory());
- Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
- Assert.That(e.Message, Text.Contains("was never used to filter classes nor collections."));
+ var memoryAppender = new MemoryAppender();
+ BasicConfigurator.Configure(memoryAppender);
+ try
+ {
+ cfg.BuildSessionFactory();
+
+ var wholeLog = String.Join("\r\n", memoryAppender.GetEvents().Select(x => x.RenderedMessage).ToArray());
+ Assert.That(wholeLog, Text.Contains("filter-def for filter named"));
+ Assert.That(wholeLog, Text.Contains("was never used to filter classes nor collections."));
+ }
+ finally
+ {
+ LogManager.Shutdown();
+ }
}
}
}
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: bugtraq:logregex
+ NH-\d+
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Fixture.cs 2010-01-13 15:56:35 UTC (rev 4917)
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Transactions;
+using NHibernate.Impl;
+using NUnit.Framework;
+using NHibernate.Criterion;
+
+namespace NHibernate.Test.NHSpecificTest.NH2065
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ using (var s = OpenSession())
+ using (s.BeginTransaction())
+ {
+ var person = new Person
+ {
+ Children = new HashSet<Person>()
+ };
+ s.Save(person);
+ var child = new Person();
+ s.Save(child);
+ person.Children.Add(child);
+
+ s.Transaction.Commit();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var s = OpenSession())
+ using (s.BeginTransaction())
+ {
+ s.Delete("from Person");
+ s.Transaction.Commit();
+ }
+ }
+
+ [Test]
+ [ExpectedException(
+ ExpectedException=typeof(HibernateException),
+ ExpectedMessage="reassociated object has dirty collection: NHibernate.Test.NHSpecificTest.NH2065.Person.Children")]
+ public void GetGoodErrorForDirtyReassociatedCollection()
+ {
+ Person person;
+ using (var s = OpenSession())
+ using (s.BeginTransaction())
+ {
+ person = s.Get<Person>(1);
+ NHibernateUtil.Initialize(person.Children);
+ s.Transaction.Commit();
+ }
+
+ person.Children.Clear();
+
+ using (var s = OpenSession())
+ using (s.BeginTransaction())
+ {
+ s.Lock(person, LockMode.None);
+ }
+ }
+
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Mappings.hbm.xml 2010-01-13 15:56:35 UTC (rev 4917)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH2065">
+
+ <class name="Person">
+ <id name="Id">
+ <generator class="increment" />
+ </id>
+ <property name="Name"/>
+
+ <set name="Children">
+ <key column="ParentId"/>
+ <one-to-many class="Person"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2065/Model.cs 2010-01-13 15:56:35 UTC (rev 4917)
@@ -0,0 +1,12 @@
+using System.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH2065
+{
+ public class Person
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+ public virtual ICollection<Person> Children { get; set; }
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-10 19:01:42 UTC (rev 4916)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-01-13 15:56:35 UTC (rev 4917)
@@ -692,6 +692,8 @@
<Compile Include="NHSpecificTest\NH2011\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2011\Model.cs" />
<Compile Include="NHSpecificTest\NH2030\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2065\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2065\Model.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
<Compile Include="NHSpecificTest\NH473\Fixture.cs" />
<Compile Include="NHSpecificTest\NH473\Parent.cs" />
@@ -2105,6 +2107,7 @@
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH2065\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1989\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1978\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2044\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|