After debugging a bug for half a day, it was found that it was related to the NHibernate transparent proxy.
I verified it with the test code:
ClassA has two attributes: S1 and S2. S1 uses nhib.pdf for persistence and S2 does not need persistence.
Public class ClassA
{
Private int _ id;
Private string _ s1;
Private string _ s2;
Public virtual int ID
{
Get {return this. _ id ;}
Set {this. _ id = value ;}
}
Public virtual string S1
{
Get {return this. _ s1 ;}
Set {this. _ s1 = value ;}
}
Internal virtual string S2
{
Get {return this. _ s2 ;}
}
Public virtual ClassA DoSomething (string s1, string s2)
{
This. _ s1 = s1;
This. _ s2 = s2;
Return this;
}
}
<? Xml version = "1.0" encoding = "UTF-8"?>
<Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.2" namespace = "AA. CMS" assembly = "aa. cms">
<Class name = "ClassA" table = "TableA">
<Id name = "ID">
<Column name = "ID" SQL-type = "NUMBER (8, 0)" not-null = "true"/>
<Generator class = "assigned"/>
</Id>
<Property name = "S1">
<Column name = "S1" SQL-type = "NVARCHAR2" length = "25" not-null = "false"/>
</Property>
</Class>
</Hibernate-mapping>
Public class ClassB
{
Public string Get (ClassA)
{
Return a. S2;
}
}
Test code: [Test]
Public void Test ()
{
ISession session = TestSetup. GetSession ();
ClassA a1 = session. Load <ClassA> (1 );
ClassA a2 = a1.DoSomething ("xxx", "yyy ");
ClassB B = new ClassB ();
DebugUtil. Output (a1.GetType (). FullName );
DebugUtil. Output (a1.S1 + "---" + B. Get (a1 ));
DebugUtil. Output (a2.GetType (). FullName );
DebugUtil. Output (a2.S1 + "---" + B. Get (a2 ));
Session. Close ();
}
Output result:
CProxyTypeAA_CMSClassACMS_NHibernate_ProxyINHibernateProxy1
Xxx ---
AA. CMS. ClassA
Xxx --- yyy
The object returned by session. Load () is a transparent proxy. When you access the public method of this transparent proxy(Nhib.pdf requires these methods to be virtual and used to inherit from it to implement transparent proxy objects)To construct the actual object.
The problem is manifested in the ClassB. Get () method. It accesses an internal type attribute S2. When a transparent proxy is passed in, the internal attribute S2 cannot be obtained. It may be that the transparent proxy has a problem in internal Method Processing.
If you want to use the congestion Model Based on nhib, pay attention to some side effects of transparent proxy.