java 如何使用标记连接hibMap文件中的两列< join>?

hrirmatl  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(75)

我需要将一个类Map到两个表(都有多个列主键)。假设TABLE 1有id 1,id 2,id 3,TABLE 2有id 1,id 2作为主键。现在,在编写Map文件时,我将做如下操作:

<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标记只接受一个key标记!如何Map第二个Id?

n7taea2i

n7taea2i1#

<key>可以包含多个<column>元素:

<key>
    <column name = "id1" />
    <column name = "id2" />
    <column name = "id3" />
</key>

相关问题