title: How to do this Unidirectional NHibernate one-to-one mapping?
body: <p>This is a problem of unidirectional one-to-one mapping in NHibernate.</p>
  
  <h2>Student.cs</h2>
  
  <pre><code>public class Student
  {
      public int ID { get; set; }
      public int Roll { get; set; }
      public int RegNo { get; set; }
      public string Name { get; set; }
  
      public StudentDetail StudentDetail { get; set; }
  }
  </code></pre>
  
  <h2>StudentDetail.cs</h2>
  
  <pre><code>public class StudentDetail
  {
      public int ID { get; set; }
  
      public string Father { get; set; }
      public string Mother { get; set; }
  }
  </code></pre>
  
  <p>How can I map these classes (how do the hbm mapping files look like) to the following case of one-to-one relationship?</p>
  
  <p><img src="https://farm5.static.flickr.com/4026/4678594717_3127393e6b_d.jpg" alt="alt text"></p>
  
  <p>Please have a look at the classes and the table very carefully. </p>
  
  <p>Where can I put the <code>&lt;many-to-one&gt;</code> tag in <code>Student.hbm.xml</code> or <code>StudentDetail.hbm.xml</code>? If I put it in <code>Student.hbm.xml</code>, how can I map the column <code>StudentDetail.StudentID</code>, coz it is in a different table?</p>
  
  <p>So this mapping:</p>
  
  <pre><code>&lt;class name="Student" table="Student"&gt;
      &lt;id name="ID" column="ID"&gt;
        &lt;generator class="native"/&gt;
      &lt;/id&gt;
  
      .......
  
      &lt;many-to-one class="StudentDetail" name="StudentDetail" column="StudentID" unique="true" cascade="all" /&gt;
    &lt;/class&gt;
  </code></pre>
  
  <p>generates the following exception:</p>
  
  <pre><code>{"Invalid column name 'StudentID'."}
  </code></pre>
  
  <p>On the other hand <code>&lt;many-to-one&gt;</code> can't be placed in <code>StudentDetail.hbm.xml</code>. Coz, <code>StudentDetail.cs</code> doesn't contain any property of type <code>Student</code>.</p>
  
  <p>Can I use <code>&lt;one-to-one&gt;</code>-tag? If yes where should I place it, in <code>Student.cs</code> or <code>StudentDetail.cs</code>? And how should I configure it?</p>