【问题标题】:Hibernate : How to do association mapping for composite key in HBM fileHibernate:如何对 HBM 文件中的复合键进行关联映射
【发布时间】:2012-08-31 03:29:09
【问题描述】:

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

【问题讨论】:

    标签: java hibernate jakarta-ee hibernate-mapping


    【解决方案1】:
    <many-to-one
            name="specialRule"
            column="SPECIAL_RULE"
            class="ClassName"
            not-null="true" lazy="true"
    
    
        >
    

    在 Rule.hbm.xml 文件中设置 lazy="true"

    【讨论】:

    • Special Day 具有包含 name 和 specialRule 的复合键,那么它将如何决定从表中获取关联的 SpecialDayData 对象?
    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多