|
From: <fab...@us...> - 2009-06-16 05:19:29
|
Revision: 4484
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4484&view=rev
Author: fabiomaulo
Date: 2009-06-16 05:19:27 +0000 (Tue, 16 Jun 2009)
Log Message:
-----------
Fix NH-1069
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Collection/AbstractPersistentCollection.cs
trunk/nhibernate/src/NHibernate/LazyInitializationException.cs
trunk/nhibernate/src/NHibernate/Proxy/AbstractLazyInitializer.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Domain.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/ImproveLazyExceptionFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Collection/AbstractPersistentCollection.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Collection/AbstractPersistentCollection.cs 2009-06-16 02:43:15 UTC (rev 4483)
+++ trunk/nhibernate/src/NHibernate/Collection/AbstractPersistentCollection.cs 2009-06-16 05:19:27 UTC (rev 4484)
@@ -478,7 +478,8 @@
private void ThrowLazyInitializationException(string message)
{
- throw new LazyInitializationException("failed to lazily initialize a collection"
+ var ownerEntityName = role == null ? "Unavailable" : StringHelper.Qualifier(role);
+ throw new LazyInitializationException(ownerEntityName, key, "failed to lazily initialize a collection"
+ (role == null ? "" : " of role: " + role) + ", " + message);
}
Modified: trunk/nhibernate/src/NHibernate/LazyInitializationException.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/LazyInitializationException.cs 2009-06-16 02:43:15 UTC (rev 4483)
+++ trunk/nhibernate/src/NHibernate/LazyInitializationException.cs 2009-06-16 05:19:27 UTC (rev 4484)
@@ -14,14 +14,31 @@
/// <summary>
/// Initializes a new instance of the <see cref="LazyInitializationException"/> class.
/// </summary>
+ /// <param name="entityName">The name of the entity where the exception was thrown</param>
+ /// <param name="entityId">The id of the entity where the exception was thrown</param>
/// <param name="message">The message that describes the error. </param>
- public LazyInitializationException(string message) : this(message, null)
+ public LazyInitializationException(string entityName, object entityId, string message)
+ : this(string.Format("Initializing[{0}#{1}]-{2}", entityName, entityId, message))
{
+ EntityName = entityName;
+ EntityId = entityId;
}
+ public string EntityName { get; private set; }
+ public object EntityId { get; private set; }
+
/// <summary>
/// Initializes a new instance of the <see cref="LazyInitializationException"/> class.
/// </summary>
+ /// <param name="message">The message that describes the error. </param>
+ public LazyInitializationException(string message)
+ : this(message, null)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LazyInitializationException"/> class.
+ /// </summary>
/// <param name="innerException">
/// The exception that is the cause of the current exception. If the innerException parameter
/// is not a null reference, the current exception is raised in a catch block that handles
Modified: trunk/nhibernate/src/NHibernate/Proxy/AbstractLazyInitializer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Proxy/AbstractLazyInitializer.cs 2009-06-16 02:43:15 UTC (rev 4483)
+++ trunk/nhibernate/src/NHibernate/Proxy/AbstractLazyInitializer.cs 2009-06-16 05:19:27 UTC (rev 4484)
@@ -55,15 +55,15 @@
{
if (_session == null)
{
- throw new LazyInitializationException("Could not initialize proxy - no Session.");
+ throw new LazyInitializationException(_entityName, _id, "Could not initialize proxy - no Session.");
}
else if (!_session.IsOpen)
{
- throw new LazyInitializationException("Could not initialize proxy - the owning Session was closed.");
+ throw new LazyInitializationException(_entityName, _id, "Could not initialize proxy - the owning Session was closed.");
}
else if (!_session.IsConnected)
{
- throw new LazyInitializationException("Could not initialize proxy - the owning Session is disconnected.");
+ throw new LazyInitializationException(_entityName, _id, "Could not initialize proxy - the owning Session is disconnected.");
}
else
{
@@ -120,7 +120,7 @@
if (value != null && IsConnectedToSession)
{
//TODO: perhaps this should be some other RuntimeException...
- throw new LazyInitializationException("Illegally attempted to associate a proxy with two open Sessions");
+ throw new LazyInitializationException(_entityName, _id, "Illegally attempted to associate a proxy with two open Sessions");
}
else
{
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Domain.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Domain.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Domain.cs 2009-06-16 05:19:27 UTC (rev 4484)
@@ -0,0 +1,10 @@
+using Iesi.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH1069
+{
+ public class LazyE
+ {
+ public virtual string Name { get; set; }
+ public virtual ISet<string> LazyC { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/ImproveLazyExceptionFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/ImproveLazyExceptionFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/ImproveLazyExceptionFixture.cs 2009-06-16 05:19:27 UTC (rev 4484)
@@ -0,0 +1,72 @@
+using System;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1069
+{
+ [TestFixture]
+ public class ImproveLazyExceptionFixture: BugTestCase
+ {
+ [Test]
+ public void LazyEntity()
+ {
+ object savedId = 1;
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Save(new LazyE(), 1);
+ t.Commit();
+ }
+
+ LazyE le;
+ using (ISession s = OpenSession())
+ {
+ le = s.Load<LazyE>(savedId);
+ }
+ string n;
+ var ex = Assert.Throws<LazyInitializationException>(() => n= le.Name);
+ Assert.That(ex.EntityName, Is.EqualTo(typeof (LazyE).FullName));
+ Assert.That(ex.EntityId, Is.EqualTo(1));
+ Assert.That(ex.Message, Text.Contains(typeof(LazyE).FullName));
+ Assert.That(ex.Message, Text.Contains("#1"));
+ Console.WriteLine(ex.Message);
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.CreateQuery("delete from LazyE").ExecuteUpdate();
+ t.Commit();
+ }
+ }
+
+ [Test]
+ public void LazyCollection()
+ {
+ object savedId=1;
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Save(new LazyE(), savedId);
+ t.Commit();
+ }
+
+ LazyE le;
+ using (ISession s = OpenSession())
+ {
+ le = s.Get<LazyE>(savedId);
+ }
+ var ex = Assert.Throws<LazyInitializationException>(() => le.LazyC.GetEnumerator());
+ Assert.That(ex.EntityName, Is.EqualTo(typeof(LazyE).FullName));
+ Assert.That(ex.EntityId, Is.EqualTo(1));
+ Assert.That(ex.Message, Text.Contains(typeof(LazyE).FullName));
+ Assert.That(ex.Message, Text.Contains("#1"));
+ Assert.That(ex.Message, Text.Contains(typeof(LazyE).FullName + ".LazyC"));
+
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.CreateQuery("delete from LazyE").ExecuteUpdate();
+ t.Commit();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1069/Mappings.hbm.xml 2009-06-16 05:19:27 UTC (rev 4484)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1069"
+ assembly="NHibernate.Test">
+ <class name="LazyE">
+ <id type="int"/>
+ <property name="Name"/>
+ <set name="LazyC">
+ <key column="leid"/>
+ <element column="LValue"/>
+ </set>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-16 02:43:15 UTC (rev 4483)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-16 05:19:27 UTC (rev 4484)
@@ -356,6 +356,8 @@
<Compile Include="NHSpecificTest\ElementsEnums\Something.cs" />
<Compile Include="NHSpecificTest\NH1044\Domain.cs" />
<Compile Include="NHSpecificTest\NH1044\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1069\Domain.cs" />
+ <Compile Include="NHSpecificTest\NH1069\ImproveLazyExceptionFixture.cs" />
<Compile Include="NHSpecificTest\NH1092\Domain.cs" />
<Compile Include="NHSpecificTest\NH1092\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1093\Fixture.cs" />
@@ -1914,6 +1916,7 @@
<EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" />
<EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1069\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1837\Mappings.hbm.xml" />
<EmbeddedResource Include="TypesTest\MultiTypeEntity_WithSqlType.hbm.xml" />
<EmbeddedResource Include="TypesTest\MultiTypeEntity_WithColumnNode.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|