title: Hibernate foreign key is primary key
body: <pre><code>DB Table REQUEST:
  {
     primary key REQUEST_ID,
     String REQUEST_DETAILS
  }
  
  DB Table INVALID_REQUEST_DETAILS{
     (foreign key, primary key) fk_req_id references REQUEST.REQUEST_ID,
     String INVALID_COMMENTS,
     String APPROVER_NAME
  }
  </code></pre>
  
  <p>So as you can see there is one REQUEST to one INVALID_REQUEST_DETAILS. For some reason which I do not understand, I have heard that Hibernate maps this as a many-to-one relationship. I have the following code for my .hbm.xml file:</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
    &lt;class name="InvalidRequestDetails" table="INVALID_REQUEST_DETAILS"&gt;  
    &lt;id name="id" column="fk_req_id"&gt;
      &lt;generator class="foreign"&gt;
          &lt;param name="property"&gt;request&lt;/param&gt;
      &lt;/generator&gt;
    &lt;/id&gt;
  
    ... (other column mappings omitted) ...    
  
    &lt;many-to-one name="request" class="Request" unique="true" not-null="true" /&gt;
   &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Please don't refer me to "read the hibernate documentation" unless you also provide some explanation, it contains very sparse explanations of concepts and I have already read it. The problem I am having is that my mapping file is obviously wrong since I can't insert any records into my table.  </p>
  
  <p>Questions:</p>
  
  <ol>
  <li>How can I fix my .hbm.xml file? Why?</li>
  <li>If I have a logically one-to-one relationship as I explained above, why do I need a many-to-one tag? What's really the difference between many-to-one and one-to-one here? When do you use which? Would anything change if my foreign key was NOT also a primary key?</li>
  </ol>