title: "Invalid Index n for this SqlParameterCollection with Count=n" OR "foreign key cannot be null"
body: <p>I have been successfully using NHibernate for quite some time now and 
  have been able to solve a lot of pitfalls with an application that I 
  developed with it and that is running in production. The recent hurdle 
  really has me scratching my head, though. </p>
  
  <p>Recently I had to expand the class library with some new classes that 
  are nested as children to some already existing classes. I just copied 
  the same model for aggregate mapping that I already was successfully 
  using, but this time it does not work. </p>
  
  <p>Now when I use the following in the parent mapping file: </p>
  
  <pre><code>  &lt;bag name="SeaInfoItems" table="EDIImport_SeaInfo" lazy="false" cascade="save-update"&gt; 
       &lt;key column="EDI_FK_OWNERID"/&gt; 
       &lt;one-to-many class="FargoGate.AppLib.EdiImportSeaInfo, FargoGate.AppLib"/&gt; 
    &lt;/bag&gt; 
  </code></pre>
  
  <p>I can choose to, in the child class, either use: </p>
  
  <pre><code>  &lt;property name="EDI_FK_OWNERID" column="EDI_FK_OWNERID" /&gt; 
  </code></pre>
  
  <p>...which gives me the infamous "Invalid Index n for this 
  SqlParameterCollection with Count=n" error. </p>
  
  <p>OR I try with this solution I found after some Googling: </p>
  
  <pre><code>   &lt;property name="EDI_FK_OWNERID" column="EDI_FK_OWNERID" insert="false" update="false" /&gt; 
  </code></pre>
  
  <p>...which gives me a "Cannot insert the value NULL into column 
  'EDI_FK_OWNERID'... column does not allow nulls." error. </p>
  
  <p>So basically I have to choose between pest and cholera. </p>
  
  <p>What I don't get is that it works flawlessly for the already existing 
  aggregate classes, and I really cannot spot the difference. The only 
  thing is that this foreign key (EDI_FK_OWNERID) could refer to two 
  different parent tables. Bad database design, I know, but I didn't 
  design it, and it is my task to develop up to it for better or worse. I cannot change the database design. </p>
  
  <p>The other difference is that I totally removed the foreign key reference from the already existing child classes (the mappings as well as the class members). I tried to emulate that of course, but of no avail.</p>
  
  <p>Also I discovered that one of the new classes (which is quite small) also works fine. But I cannot see what the difference is here either. I am stumped! </p>
  
  <p>Anyone has a clue? </p>