gpt4 book ai didi

java - 在复合键 hibernate xml 中映射复合键

转载 作者:行者123 更新时间:2023-11-30 06:34:22 27 4
gpt4 key购买 nike

这就是我想要做的,将一个对象映射到另一个具有相同主键的表。下面是一个示例,基本上我有一个带有复合键的对象,该对象具有另一个表的复合键,但我不知道如何将两者都包括在内以创建正确的对象键。我突出显示了错误的行,它只包含键的一个属性。

  <class name="BusinessRuleObject" table="BUSINESS_RULE_OBJECTS" schema="DB">
<composite-id name="businessRuleObjectId" class="BusinessRuleObjectId">
<key-property name="sameIdCode" column="ID_CD" />
**<key-many-to-one name="businessRule" class="BusinessRule" column="BUSINESS_RULE" />**
</composite-id>
<!-- ... STUFF GOES HERE -->
</class>

<class name="BusinessRule" table="BUSINESS_RULE_STRINGS" schema="DB">
<composite-id name="businessRule2ID" class="BusinessRule2ID">
<key-property name="sameIdCode" column="ID_CD" />
<key-property name="businessRuleCode" column="BUSINESS_RULE" />
</composite-id>
<!-- TOTALLY DIFFERENT STUFF GOES HERE -->
</class>

最佳答案

复合外键只有一个属性businessRule包括在内,因为 <key-many-to-one只声明一列 BUSINESS_RULE .它应该声明它引用的复合键的两列 BUSINESS_RULEID_CD在你的例子中。通过添加 ID_CD列到 <key-many-to-one您需要删除或重命名 <key-property name="sameIdCode" column="ID_CD" /> 列的元素元素。

协会<key-many-to-onebusinessRule对象应该像这样映射:

<composite-id name="businessRuleObjectId" class="BusinessRuleObjectId"> 

<key-many-to-one name="businessRule" class="BusinessRule" >
<column name="ID_CD" />
<column name="BUSINESS_RULE" />
</key-many-to-one>

</composite-id>

Hibernate reference documenation
5.1.7. composite-id
Components as composite identifiers

关于java - 在复合键 hibernate xml 中映射复合键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7070150/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com