title: NHibernate: Two foreign keys in the same table against same column
body: <p>I am working on a consignment booking software.
  The consignment object has the following structure:</p>
  
  <pre><code>public class Consignment
  {
     //Other properties
  
     public virtual Station FromStation{get;set;}
  
     public virtual Station ToStation{get;set;}
  }
  </code></pre>
  
  <p>and here is the station object:</p>
  
  <pre><code>public class Station
  {
     public virtual int StationId{get;set;}
  
     public virtual string StationName{get;set;}
  
      //I don't want this property but I have to keep it.
      public virtual Iesi.Collections.Generic.ISet&lt;Consginment&gt; ConsginmentFrom
      {
          get;
          set;
      }
  
      //I don't want this property but I have to keep it here.
      public virtual Iesi.Collections.Generic.ISet&lt;Consginment&gt; ConsginmentTo
      {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>In the database side, there would be a Station table, and the Consignment table would have two int columns (called FromStation and ToStation), storing the ids of the station.</p>
  
  <p>I am not much of an NHibernate guy, after googling and reading for half a day I came up with the following Mapping Files:</p>
  
  <p>Station.hbm.xml</p>
  
  <pre><code>&lt;class name="Station" table="Station"&gt;
      &lt;id name="StationId" &gt;
        &lt;column name="STATION_ID" not-null="true" /&gt;
        &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="StationName" &gt;
        &lt;column name="STATION_NAME" not-null="true"  /&gt;
      &lt;/property&gt;
      &lt;set name="ConsginmentFrom" inverse="true" lazy="true" generic="true"&gt;
        &lt;key&gt;
          &lt;column name="StationId" /&gt;
        &lt;/key&gt;
        &lt;one-to-many class="Consignment" /&gt;
      &lt;/set&gt;
      &lt;set name="ConsignmentTo" inverse="true" lazy="false" generic="true"&gt;
        &lt;key&gt;
          &lt;column name="StationId" /&gt;
        &lt;/key&gt;
        &lt;one-to-many class="Consignment" /&gt;
      &lt;/set&gt;
    &lt;/class&gt;
  </code></pre>
  
  <p>Consignment.hbm.xml</p>
  
  <pre><code>&lt;class name="Consignment" abstract="true"
             table="Consignment" lazy="false"&gt;
      &lt;id name="ConsignmentId"&gt;
        &lt;generator class="hilo"/&gt;
      &lt;/id&gt;
  
    &lt;!--Column mapping for other properties--&gt;
  
      &lt;many-to-one name="FromStation" class="Station"&gt;
        &lt;column name="STATION_ID" not-null="true" /&gt;
      &lt;/many-to-one&gt;
  
      &lt;many-to-one name="ToStation" class="Station"&gt;
        &lt;column name="STATION_ID" not-null="true" /&gt;
      &lt;/many-to-one&gt;
  
  
    &lt;/class&gt;
  </code></pre>
  
  <p>But the above is generating strange DB structure.
  I have to do it xml mapping files as a lot has already been written in xml.
  Am I doing it correctly? Can there be a better way?</p>
  
  <p>Thanks for reading this.</p>