Superkey包含三个属性 - 如何应对Hibernate?

时间:2010-07-05 02:44:47

标签: java hibernate orm

考虑与三个属性的候选键的关系:

enter image description here

我想知道是否有人能给我一个Hibernate配置文件的例子?

1 个答案:

答案 0 :(得分:1)

...
<class name="Topic" table="topics">
    ...
    <set name="candidatures" table="Topic_has_Count_has_Date">
        <key column="TOPIC_ID"/>
        <composite-element class="TopicCountDate">
            <parent name="topic"/>
            <many-to-one name="count" class="Count" column="COUNT_ID"/>
            <many-to-one name="date" class="Date" column="DATE_ID"/>
        </composite-element>
    </set>
</class>
<class name="Date" table="dates">
    ...
    <set name="candidatures" table="Topic_has_Count_has_Date">
        <key column="DATE_ID"/>
        <composite-element class="TopicCountDate">
            <parent name="date"/>
            <many-to-one name="count" class="Count" column="COUNT_ID"/>
            <many-to-one name="topic" class="Topic" column="TOPIC_ID"/>
        </composite-element>
    </set>
</class>
<class name="Count" table="counts">
    ...
    <set name="candidatures" table="Topic_has_Count_has_Date">
        <key column="COUNT_ID"/>
        <composite-element class="TopicCountDate">
            <parent name="count"/>
            <many-to-one name="date" class="Date" column="DATE_ID"/>
            <many-to-one name="topic" class="Topic" column="TOPIC_ID"/>
        </composite-element>
    </set>
</class>