Proxy object backing field is null though property has value #3589
-
While i was working on a bug fix i noticed that when accessing the backing field of a proxy object it can sometimes be null, while the property itself is populated with the expected value i've found anecdotal evidence online whilst researching that this can just be a thing that happens with nhibernate but not really been able to locate a clear/official answer as to why or how to avoid in the future or if this is a bug or not. in my testing this seems to occur when accessing the backing field via a different instance of the domain model - are there any other situations this might occur? here is a code sample to reproduce - relevant access happens inside LogNameForReference
Reference.hbm.xml
Resource.hbm.xml
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Don’t access fields you don’t own, even if you can. The field you’re trying to access is an unintialized field of a proxy object. The proxy has a reference to the instance object whose fields are getting initialized. This is done this way for the reason of inheritance. The only fields you can access directly are the fields of the |
Beta Was this translation helpful? Give feedback.
Don’t access fields you don’t own, even if you can.
The field you’re trying to access is an unintialized field of a proxy object. The proxy has a reference to the instance object whose fields are getting initialized. This is done this way for the reason of inheritance.
The only fields you can access directly are the fields of the
this
object. Other objects’ fields should be accessed through properties or you need to explicitly unwrap the proxy.