title: How to map a bag with composite key with NHibernate
body: <p>Im trying to map two objects with NHibernate</p>
  
  <p>This is my first object "Asociado" composed by "Justificaciones", next to it is "Justificacion" which has a composed key</p>
  
  <pre><code>public class Justificacion
  {
      private int _id; //(PK) 
      private Asociado _asociado;(FK)
  
      public override bool Equals(object obj)
      {
  
          return base.Equals(obj);
  
      }
  
      public override int GetHashCode()
      {
          return base.GetHashCode();
      }
  
      public override string ToString()
      {
          return base.ToString();
      }
  
      public virtual int Id
      {
          get { return _id; }
          set { _id = value; }
      }
  
      public virtual Asociado Asociado
      {
          get { return _asociado; }
          set { _asociado = value; }
      }
  }
  
  public class Asociado
  {
      private int _id;
      private IList&lt;Justificacion&gt; _justificaciones;
  
      public virtual int Id
      {
          get { return this._id; }
          set { this._id = value; }
      }
  
      public virtual IList&lt;Justificacion&gt; Justificaciones
      {
          get { return _justificaciones; }
          set { _justificaciones = value; }
      }
  }
  </code></pre>
  
  <p>this is the mapping i did, but is not working</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                     assembly="Trascend.Bolet.ObjetosComunes"
                     namespace="Trascend.Bolet.ObjetosComunes.Entidades"&gt;
  
    &lt;class name="Justificacion" table="FAC_ASO_JUST"&gt;
      &lt;composite-id&gt;
        &lt;key-property name="Id" column="CCARTA" type="int"&gt;&lt;/key-property&gt;
        &lt;key-property name="Asociado" column="CASOCIADO" type="int"&gt;&lt;/key-property&gt;
      &lt;/composite-id&gt;
  
      &lt;many-to-one name="Asociado" class="Asociado"&gt;
        &lt;column name="CASOCIADO"/&gt;
      &lt;/many-to-one&gt;
  
  
    &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  
  
  &lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                     assembly="Trascend.Bolet.ObjetosComunes"
                     namespace="Trascend.Bolet.ObjetosComunes.Entidades"&gt;
  
    &lt;class name="Asociado" table="FAC_ASOCIADOS"&gt;
      &lt;id name="Id" column="CASOCIADO" /&gt;
  
    &lt;bag name="Justificaciones"
            fetch="join"
            inverse="true"
            cascade="save-update"&gt;
      &lt;key&gt;
        &lt;column name="CCARTA"/&gt;
        &lt;column name="CASOCIADO"/&gt;
      &lt;/key&gt;
      &lt;one-to-many class="Justificacion"/&gt;
    &lt;/bag&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>