title: NHibernate Many to many mapping with additional columns in the mapping table
body: <p>There are two tables Person and Address. I have a mapping table PersonAddressMap which contains an additional column IsCurrent other than the two foreign keys (no explicit primary key column). I have created three mapping classes one each for Person, Address and PersonAddressMap. I need to access all the Addresses of a Person and also access all the Persons who have a particular address from Address, so I have a one-to-many to PersonAddressMap in both the Person and Address class. Now the problem is bi-directional association is creating an infiniteloop. If I remove one of the associations, the load is working fine, but Save is not inserting into the mapping table (Eg: If I have only one association from Person to PersonAddressMap and try to insert a new Person with new address then only Person is getting inserted.). The mapping files look like this,</p>
  
  <pre><code>  &lt;class name="Person" table="Person"&gt;
  
      &lt;id name="Id"&gt;  
        &lt;column name="Id" sql-type="int" not-null="true" /&gt;
        &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="Name" column="Name"/&gt;
      &lt;bag name="AddressDetails" table="PersonAddressMap" cascade="all" &gt;
        &lt;key column="PersonId" /&gt;
        &lt;one-to-many class="PersonAddressMap" /&gt;
      &lt;/bag&gt;
    &lt;/class&gt;
  
    &lt;class name="Address" table="Address"&gt;
  
      &lt;id name="Id"&gt;  
        &lt;column name="Id" sql-type="int" not-null="true" /&gt;
        &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="City" column="City"/&gt;
      &lt;bag name="PersonDetails" table="PersonAddressMap" cascade="all" &gt;
        &lt;key column="AddressId" /&gt;
        &lt;one-to-many class="PersonAddressMap" /&gt;
      &lt;/bag&gt;
    &lt;/class&gt;
  
    &lt;class name="Job" table="Job" lazy="false"&gt;
      &lt;composite-id&gt;
        &lt;key-many-to-one column="PersonId" name="Person" /&gt;
        &lt;key-many-to-one column="AddressId" name="Address" /&gt;
      &lt;/composite-id&gt;
      &lt;property name="IsCurrent" column="IsCurrent"/&gt;
    &lt;/class&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>