domain model exception badly handled by proxy NHibernate
Description
Hi, I`m expecting some trouble when one of my domain classes throw an exception and the object is lazy initialized. I put a handler for the exception but I receive a TargetInvocationException. The proxy should rethrow the inner exception of the TargetInvocationException. The attachment has the test case. I need to fix this bug, could you help me? The example:
//load the configuration Configuration cfg = new Configuration(); String dir = "C: Documents and Settings Esteban Robles\\workspace\\Cimed\\cimed\\controlEquipos\\ModuloControlEquipos\\NHibernateLazy\\Mappings "; cfg.AddFile(dir + "Mapping.hbm.xml");
//export the schema new SchemaExport(cfg).Create(false, true);
//store an object ISessionFactory sf = cfg.BuildSessionFactory(); A a = new A(); B b = new B(); a.B = b;
ISession s = sf.OpenSession(); ITransaction t = s.BeginTransaction(); s.Save(a); t.Commit(); s.Close();
//retrieve the object s = sf.OpenSession(); IList l = s.CreateCriteria(typeof(A)).List();
Hi,
I`m expecting some trouble when one of my domain classes throw an exception and the object is lazy initialized. I put a handler for the exception but I receive a TargetInvocationException.
The proxy should rethrow the inner exception of the TargetInvocationException. The attachment has the test case.
I need to fix this bug, could you help me?
The example:
//load the configuration
Configuration cfg = new Configuration();
String dir = "C:
Documents and Settings
Esteban Robles\\workspace\\Cimed\\cimed\\controlEquipos\\ModuloControlEquipos\\NHibernateLazy\\Mappings
";
cfg.AddFile(dir + "Mapping.hbm.xml");
//export the schema
new SchemaExport(cfg).Create(false, true);
//store an object
ISessionFactory sf = cfg.BuildSessionFactory();
A a = new A();
B b = new B();
a.B = b;
ISession s = sf.OpenSession();
ITransaction t = s.BeginTransaction();
s.Save(a);
t.Commit();
s.Close();
//retrieve the object
s = sf.OpenSession();
IList l = s.CreateCriteria(typeof(A)).List();
//force the exception
try
{
((A)l[0]).execute();
}
catch (MyException e)
{
Assert.IsTrue(true);
}
catch (TargetInvocationException e)
{
Assert.IsTrue(false);
}
namespace NHibernateLazy
{
public class MyException : Exception
{
}
}
namespace NHibernateLazy
{
public class A
{
private B b;
private Int64 id;
public virtual Int64 Id
{
get { return id; }
set { id = value; }
}
public virtual B B
{
get { return b; }
set { b = value; }
}
public virtual void execute()
{
this.B.execute();
}
}
}
namespace NHibernateLazy
{
public class B
{
private Int64 id;
public virtual Int64 Id
{
get { return id; }
set { id = value; }
}
public virtual void execute()
{
throw new MyException();
}
}
}