I have the following configuration in my mapping files for 2 tables.
Table 1:
Code:
<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">
<composite-id mapped="false" unsaved-value="undefined">
<key-property name="id1" type="int">
<column name="id1"/>
</key-property>
<key-property name="id2" type="int">
<column name="id2"/>
</key-property>
</composite-id>
<property name="details" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never">
<column name="Details" length="500"/>
</property>
<one-to-one name="CompPkTestDetail" entity-name="CompPkTestDetail" constrained="false" embed-xml="true"/>
Table 2:
Code:
<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">
<composite-id mapped="false" unsaved-value="undefined">
<key-property name="idetail1" type="int">
<column name="idetail1"/>
</key-property>
<key-property name="idetail2" type="int">
<column name="idetail2"/>
</key-property>
</composite-id>
<one-to-one name="CompPkTest" entity-name="CompPkTest" constrained="true" embed-xml="true"/>
<property name="someDetail" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never">
<column name="someDetail" length="300"/>
</property>
<property name="moreDetail" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never">
<column name="moreDetail" length="300"/>
</property>
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".
My questions:
Is the above mapping xml the correct way to make this association (with the non-matching field names)?
Is Hibernate correct to impose that the field names must match, or is this a bug?
Please note that I'm using Hibernate 3.6.6 Final and in my web application there are no classes for the entities as Hibernate is in map-mode. The mapping files were originally generated using Hibernate Tools reverse engineering Ant tasks.