title: Eager loading a tree with nHibernate re-queries leaf nodes
body: <p>Looking for some expertise before I declare the NHibernate framework broken or myself crazy! </p>
  
  <p>I'm trying to eagerly load a self-referencing tree with NHibernate and can successfully load most children lists, however I can't seem to get it to work with leaf nodes.  My query is:</p>
  
  <pre><code>"select p from Proposal p join fetch p.Structures s join fetch s.theChildrenList c " +
  "where p._persistenceId = :p1 and s.theProposal = :p1 and c.theProposal = :p1")
  .SetParameter("p1", aProposalId)
  .SetResultTransformer(new DistinctRootEntityResultTransformer()).
  UniqueResult&lt;Proposal&gt;();
  </code></pre>
  
  <p>This will return all the records correctly, but does not properly populate the childrenList of leaf nodes (which should be by definition empty).  Instead when I get a proxy and upon searching the tree, thousands of pointless zero record queries.</p>
  
  <p>I've tried:
  1. using left join rather than join 
  2. Making the children's list not-lazy and fetch="join" and removing the hql (as a proof of concept, performance downside is unacceptable elsewhere)
  3. Messing with the not-found property that I saw someone use in the hibernate forums</p>
  
  <p>All of which give me the same results... one large query with all the data (good) and thousands of small queries which return no data (bad).  Any ideas?</p>
  
  <p>I'm using NHibernate 2.2 and here is the relevant part of the mappings file for reference:</p>
  
  <pre><code>  &lt;many-to-one    name="theParentStructure"
                    column="PARENT_STRUCTURE_ID"
                    class="Structure"
                    access="field"
                    update="false"
                    insert="false"
                    not-found="ignore"/&gt;
  
    &lt;bag            name="theChildrenList"
                    generic="true"
                    table="STRUCTURE"
                    access="field"
                    cascade="all-delete-orphan"
                    inverse="true" fetch="join" lazy="false"&gt;  &lt;--Both with and without the last two properties
       &lt;key column="PARENT_STRUCTURE_ID" /&gt;
       &lt;one-to-many class="Structure"/&gt;
    &lt;/bag&gt;
  </code></pre>
  
  <p>Any help would be appreciated!!</p>