簡體   English   中英

Hibernate:如何對HBM文件中的組合鍵進行關聯映射

[英]Hibernate : How to do association mapping for composite key in HBM file

問題 :有兩個表,名為specialdayrule 。在規則表中,名為specialrule的一列引用specialday表,並希望以某種方式制作rule.hbm.xml文件,以便當我從表中獲取規則對象時也將獲取關聯的specialday賓語。 在這里,我寫下了specialdaydata.hbm.xmlrule.hbm.xml

  • SpecialDayData.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>

  • Rule.hbm.xml

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM