当我在一个表上有一个复合键而另一个表只有1个pk时,是否可以一对一地具有休眠xml映射?当我进行以下设置时,出现“ Foreign key必须具有与主键引用相同的列数”错误(请注意,im仅尝试映射B和C; A用于上下文):表A具有1与B有很多关系。B与C有一对一关系:
表A:
+----+--------+
| | Column |
+----+--------+
| PK | id1 |
| | |
+----+--------+
表B:
+----+--------+
| | Column |
+----+--------+
| PK | id2 |
| FK | id1 |
+----+--------+
表C:
+-------+--------+
| | Column |
+-------+--------+
| PK FK | id1 |
| PK FK | id2 |
+-------+--------+
XML
<hibernate-mapping>
<class name="CClass" table="C">
<composite-id>
<key-property name="id1" column="id1"/>
<key-property name="id2" column="id2"/>
</composite-id>
<one-to-one name="bs" class="BClass" constrained="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="BClass" table="B">
<id name="id" column="id2" >
<generator class="native"/>
</id>
<one-to-one name="cs" class="CClass" constrained="true"/>
<many-to-one name="id1" column="id1" class="A"
</class>
</hibernate-mapping>