|
From: <fab...@us...> - 2009-10-14 20:23:07
|
Revision: 4746
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4746&view=rev
Author: fabiomaulo
Date: 2009-10-14 20:22:58 +0000 (Wed, 14 Oct 2009)
Log Message:
-----------
Merge r4745 (fix NH-1985)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/DomainClass.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/SampleTest.cs
Modified: trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs 2009-10-14 19:45:17 UTC (rev 4745)
+++ trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs 2009-10-14 20:22:58 UTC (rev 4746)
@@ -90,12 +90,11 @@
version = entityEntry.Version;
}
- /*if ( !persister.isMutable() ) {
- throw new HibernateException(
- "attempted to delete an object of immutable class: " +
- MessageHelper.infoString(persister)
- );
- }*/
+ if (!persister.IsMutable)
+ {
+ throw new HibernateException("Attempted to delete an object of immutable class: "
+ + MessageHelper.InfoString(persister));
+ }
if (InvokeDeleteLifecycle(source, entity, persister))
{
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/DomainClass.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/DomainClass.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/DomainClass.cs 2009-10-14 20:22:58 UTC (rev 4746)
@@ -0,0 +1,9 @@
+namespace NHibernate.Test.NHSpecificTest.NH1985
+{
+ public class DomainClass
+ {
+ public int Id { get; set; }
+
+ public string Label { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/Mappings.hbm.xml 2009-10-14 20:22:58 UTC (rev 4746)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1985"
+ default-lazy="false">
+ <class name="DomainClass" mutable="false">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="Label" />
+ </class>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/SampleTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/SampleTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1985/SampleTest.cs 2009-10-14 20:22:58 UTC (rev 4746)
@@ -0,0 +1,66 @@
+using System;
+using System.Data;
+using NHibernate.Connection;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1985
+{
+ [TestFixture]
+ public class SampleTest : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ base.OnSetUp();
+
+ if (0 == ExecuteStatement("INSERT INTO DomainClass (Id, Label) VALUES (1, 'TEST record');"))
+ {
+ throw new ApplicationException("Insertion of test record failed.");
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ base.OnTearDown();
+
+ ExecuteStatement("DELETE FROM DomainClass WHERE Id=1;");
+ }
+
+ [Test]
+ public void AttemptToDeleteImmutableObjectShouldThrow()
+ {
+ using (ISession session = OpenSession())
+ {
+ Assert.Throws<HibernateException>(() =>
+ {
+ using (ITransaction trans = session.BeginTransaction())
+ {
+ var entity = session.Get<DomainClass>(1);
+ session.Delete(entity);
+
+ trans.Commit(); // This used to throw...
+ }
+ });
+ }
+
+ using (IConnectionProvider prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties))
+ {
+ IDbConnection conn = prov.GetConnection();
+
+ try
+ {
+ using (IDbCommand comm = conn.CreateCommand())
+ {
+ comm.CommandText = "SELECT Id FROM DomainClass WHERE Id=1 AND Label='TEST record'";
+ object result = comm.ExecuteScalar();
+
+ Assert.That(result != null, "Immutable object has been deleted!");
+ }
+ }
+ finally
+ {
+ prov.CloseConnection(conn);
+ }
+ }
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-14 19:45:17 UTC (rev 4745)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-14 20:22:58 UTC (rev 4746)
@@ -617,6 +617,8 @@
<Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" />
<Compile Include="NHSpecificTest\NH1969\EntityWithTypeProperty.cs" />
<Compile Include="NHSpecificTest\NH1969\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1985\DomainClass.cs" />
+ <Compile Include="NHSpecificTest\NH1985\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1990\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1990\Model.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
@@ -2035,6 +2037,7 @@
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1985\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1990\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|