![](/img/trans.png)
[英]How do I create a composite primary key in hibernate within the hbm.xml file
[英]Hibernate : How to do association mapping for composite key in HBM file
問題 :有兩個表,名為specialday和rule 。在規則表中,名為specialrule的一列引用specialday表,並希望以某種方式制作rule.hbm.xml文件,以便當我從表中獲取規則對象時也將獲取關聯的specialday賓語。 在這里,我寫下了specialdaydata.hbm.xml和rule.hbm.xml
<composite-id name="specialDayIdData" class="SpecialDayIdData">
<key-property name="name" column="NAME" type="string"/>
<key-property name="specialRule" column="SPECIAL_RULE" type="string"/>
</composite-id>
<property name="type" type="java.lang.Integer">
<column name="TYPE" sql-type="NUMERIC" not-null="true"/>
</property>
---other column
------
</class>
<id name="rule" column="RULESTRING" type="string">
<generator class="assigned"/>
</id>
<property name="specialRule" type="string">
<column name="SPECIAL_RULE" sql-type="VARCHAR(64)" not-null="false"/>
</property>
<!--specialRule Refer SpecialDayData -->
<many-to-one >
Stuck over here
</many-to-one>
</class>
<many-to-one
name="specialRule"
column="SPECIAL_RULE"
class="ClassName"
not-null="true" lazy="true"
>
在Rule.hbm.xml文件中使lazy =“ true”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.