Hibernate:如何在HBM文件中进行复合键的关联映射

时间:2012-09-06 10:21:39

标签: java hibernate java-ee hibernate-mapping

问题:有两个表名为 specialday 规则。在规则表中,一个名为specialrule的列引用了特殊日期表并想要制作rule.hbm.xml文件的方式,以便当我从表中获取规则对象时,它还将获取关联的特殊对象。 在这里,我写下了 specialdaydata.hbm.xml rule.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>

1 个答案:

答案 0 :(得分:0)

<many-to-one
        name="specialRule"
        column="SPECIAL_RULE"
        class="ClassName"
        not-null="true" lazy="true"


    >

在Rule.hbm.xml文件中使lazy =“true”