如何使用连接 hibernate 映射文件中的两列标签?

发布于 2024-10-09 22:28:15 字数 996 浏览 5 评论 0原文

我需要将单个类映射到两个表(都具有多列主键)。假设 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>

如您所见,连接标记仅接受一个键标记!如何映射第二个 ID?

I need to map a single class to two tables (both with multiple columns primary key). Let's say TABLE1 has id1, id2, id3 and TABLE2 has id1, id2 as primary keys. Now when writing the mapping file I would do something like the following:

<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>

As you can see the join tag accepts only one key tag! How do I map the second Id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-10-16 22:28:15

可以包含多个 元素:

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

<key> may contain multiple <column> elements:

<key>
    <column name = "id1" />
    <column name = "id2" />
    <column name = "id3" />
</key>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文