Thanks for the response. I'm really trying to understand why NH is
doing things.

In my scenario I'm not trying to change anything about lazy loading. I
don't have the exact mappings on this PC but, a pseudo mapping is

<objectA lazy="true">
<many-to-one name="LastModifiedByUser" class="objectB">
<bag name="AvailableUsers" etc.>
  ...
  <many-to-one class="objectB" />
</bag>
</objectA>

<objectB lazy="true">
  <many-to-one name="ObjBParent" class="objectA" />
  ... etc.
</objectB>

I load objectA via a Get (e.g. "Get<objectA>(58)"). When I look in the
debugger at the returned class the property for "LastModifiedByUser"
is not set to a concrete objectB class but a proxied objectB class
created by NHibernate.

This is what I expect.

Later, with the same session (Open Session in View pattern). I do an
seperate HQL query such as:

FROM objectB WHERE ObjBParent.Id = 58

The query might not have been for 58, it could have been for 109 or
12234 - it's all down to user selection. This gets a collection of
objectB's. The SQL generated by the HQL is correct. Now, when I look
in the debugger I see something like:

[0] type=NHProxyclass
[1] type=objectB
[2] type=objectB
[3] type=objectB

Element [0] just so happens to refer to the same objectB as would be
lazy loaded by the "LastModifedUser" property of objectA. What NH has
NOT done is replace the proxy with the real object returned by the HQL
query.

I'd like to know why as the object is now fully loaded by the HQL
query into the session.

The reason this is a problem is, as I then bind the results to a
gridview. The bind fails as element [0] is not the same object as
object [1]. Its an annoying, but well known problem with databound
controls. The fix is meant to be to implement ITypedList and use a
custom collection. I tried this, but this does not fix the issue, it
simply changes the error I am getting.

The root of the problem though is NH. If I knew why NH did what it
did, maybe I could tune the HQL query to enforce replacement of
proxied objects but I can't see that kind of option anywhere.

I've had a couple of these recently in different situations (e.g.
Get's falling over due to proxy errors - why should a Get generate a
proxy error???) in different applications but I've not been able to
understand why NH is working the way it is.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to