我需要将单个类映射到两个表(两个表都有多列主键)。假设TABLE1具有id1,id2,id3,并且TABLE2具有id1,id2作为主键。现在,在编写映射文件时,我会执行以下操作:
<hibernate-mapping package="beans">
<class name="TABLE1Class" table="TABLE1">
<composite-id name="table1PK" class="TABLE1PKClass">
<key-many-to-one name="id1" class="ID1Class" column="id1"/>
<key-many-to-one name="id2" class="ID2Class" column="id2"/>
<key-many-to-one name="id3" class="ID3Class" column="id3"/>
</composite-id>
<property name="someProperty" type="integer" not-null="true" column="x"/>
<join table="TABLE2">
<key column="id1" />
<!-- <key column="id2"/> The join tag accepts only one key tag!!!
How do I map the second key??? -->
<property name="propertyFromTable2" type="float" not-null="true"/>
</join>
</class>
</hibernate-mapping>
正如您所看到的,join标记只接受一个键标记!如何映射第二个ID?
亲切的问候,
暴君
P.S。:圣诞快乐,快乐而富有成效的新年;)
答案 0 :(得分:2)
<key>
可能包含多个<column>
元素:
<key>
<column name = "id1" />
<column name = "id2" />
<column name = "id3" />
</key>