title: Hibernate one-to-one with composite keys
body: <p>I have an issue with my mapping file, relating to a one-to-one relationship, with composite primary keys, where the field names of the keys do not match.</p>
  
  <p>Table 1:</p>
  
  <pre><code>&lt;class entity-name="CompPkTest" table="compPkTest" catalog="data" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version"&gt;
  &lt;composite-id mapped="false" unsaved-value="undefined"&gt;
    &lt;key-property name="id1" type="int"&gt;
      &lt;column name="id1"/&gt;
    &lt;/key-property&gt;
    &lt;key-property name="id2" type="int"&gt;
      &lt;column name="id2"/&gt;
    &lt;/key-property&gt;
  &lt;/composite-id&gt;
  &lt;property name="details" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never"&gt;
    &lt;column name="Details" length="500"/&gt;
  &lt;/property&gt;
  &lt;one-to-one name="CompPkTestDetail" entity-name="CompPkTestDetail" constrained="false" embed-xml="true"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>Table 2:</p>
  
  <pre><code>&lt;class entity-name="CompPkTestDetail" table="compPkTestDetail" catalog="data" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version"&gt;
  &lt;composite-id mapped="false" unsaved-value="undefined"&gt;
    &lt;key-property name="idetail1" type="int"&gt;
      &lt;column name="idetail1"/&gt;
    &lt;/key-property&gt;
    &lt;key-property name="idetail2" type="int"&gt;
      &lt;column name="idetail2"/&gt;
    &lt;/key-property&gt;
  &lt;/composite-id&gt;
  &lt;one-to-one name="CompPkTest" entity-name="CompPkTest" constrained="true" embed-xml="true"/&gt;
  &lt;property name="someDetail" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never"&gt;
    &lt;column name="someDetail" length="300"/&gt;
  &lt;/property&gt;
  &lt;property name="moreDetail" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never"&gt;
    &lt;column name="moreDetail" length="300"/&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p></p>
  
  <p>The problem is that when querying table 1, the "details" property is null.
  If I change the key-property names in CompPkTestDetail to be id1 and id2, (while leaving the column name unchanged), the relationship works as expected, and the query returns a value for "details".</p>
  
  <p>My questions:</p>
  
  <p>Is the above mapping xml the correct way to make this association (with the non-matching field names)?</p>
  
  <p>Is hibernate correct to impose that the field names must match, or is this a bug?</p>
  
  <p>Please note that in my application there are no classes for the entities, and hibernate is in map-mode. My application has fully dynamic access to the (arbitrary) databases, and so the xml for the mappings is generated at run time.</p>