Note that there are some explanatory texts on larger screens.

plurals
  1. POCollections in dependent objects not loaded in NHibernate
    text
    copied!<p>I have a list of IUser objects which are MTM related with IRole objects. These IRole objects in turn are MTM related to IPrivilege objects.</p> <p>When retrieving an IUser object I can see all related IRole objects in the (IList) list of this IUser.</p> <p>When retrieving an IRole object I can see all related IPrivilege objects in the (IList) list of this IRole.</p> <p>But when I fetch a user and get inspect one role from that users role list the list of privileges in that role object is empty (the list is correctly initialized when fetching the role directly).</p> <p>It looks like NHibernate is not fetching related objects of related objects in my setup. What am I doing wrong? How can I make NHibernate fully initialize all the role objects in the users list of roles so that each role shows a list of associated privileges?</p> <p>BTW: Attention! I'm a NHibernate rookie!</p> <p><strong>Edit (@Firo):</strong></p> <p>These are the relation mapping fragments from IUser and IRole:</p> <p>(IUser)</p> <pre><code>... HasManyToMany&lt;HbnRole&gt;(x =&gt; x.Roles).Table("USERROLEMAP") .ParentKeyColumn("USERID") .ChildKeyColumn("ROLEID") .Cascade.All(); </code></pre> <p>(IRole)</p> <pre><code>... HasManyToMany&lt;HbnPrivilege&gt;(x =&gt; x.Privileges).Table("ROLEPRIVILEGEMAP") .ParentKeyColumn("ROLEID") .ChildKeyColumn("PRIVILEGEID") .Cascade.All(); HasManyToMany&lt;HbnUser&gt;(x =&gt; x.Users).Table("USERROLEMAP") .Inverse() .LazyLoad() .ParentKeyColumn("ROLEID") .ChildKeyColumn("USERID"); </code></pre> <p>(IPrivilege)</p> <pre><code>... HasManyToMany&lt;HbnRole&gt;(x =&gt; x.Roles).Table("ROLEPRIVILEGEMAP") .Inverse() .LazyLoad() .ParentKeyColumn("PRIVILEGEID") .ChildKeyColumn("ROLEID"); </code></pre> <p>To be honest, I have no idea how to capture the query... :-(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload