考慮將這兩個類映射到同一個表。一個是通過mutable =「false」只讀的。映射到同一個表(一次只讀)的兩個類必須按正確的順序?
<class name="Funder" table="funder">
<id name="id">
<generator class="identity" />
</id>
<property name="funder_name" />
<property name="contact_name" />
<property name="addr_line_1" />
<property name="addr_line_2" />
<property name="addr_line_3" />
<property name="city" />
<many-to-one name="state" column="state_id" foreign-key="FK_funder_state_id" fetch="join" />
<property name="zip_code" length="10" />
<property name="phone_number" length="30" />
<property name="create_dt" update="false" not-null="true" />
<many-to-one name="create_by" column="create_by" not-null="true" update="false" foreign-key="FK_funder_create_by" fetch="join" />
<property name="last_update_dt" insert="false" />
<many-to-one name="last_update_by" insert="false" foreign-key="FK_funder_last_update_by" fetch="join" />
</class>
<class name="FunderSimple" table="funder" schema-action="none" mutable="false">
<id name="id">
<generator class="identity" />
</id>
<property name="funder_name" />
<property name="contact_name" />
<property name="phone_number" />
</class>
如果我出資人之前移動FunderSimple映射映射我的架構並沒有正確產生。如果我像上面那樣離開它,它就會起作用。
設計這是什麼?看起來好像schema-action =「none」粘在table_name上,後來到同一個表的映射不會生成模式。
我這樣做是因爲我有另一個名爲Contract的類,它有一個外鍵給出資者表。但是,從合同對象引用時,我不需要所有的資助者列。
<many-to-one name="funder_simple" column="funder_id" foreign-key="FK_contract_funder_id" fetch="join" />
出資者不從FunderSimple繼承。
我是否應該使用不同的技術從外鍵表中只提取列的子集?多對一是設置外鍵的唯一方法嗎?
使用版本2.1.0.4000
有趣......但是,請問從合同角度映射這項工作。我是否會將多對一改回到繁重的Funder對象,並以某種方式將其映射到僅加載FunderSimple? – dotjoe 2009-09-02 16:06:13
合同應與「資助者」有關係,因爲「資助者」是您的實體。 我只看到FunderSimple只是作爲某種助手/容器來顯示「資助者」列表,而您並不需要擁有完整的資助者實體。 爲什麼要在檢索合同實例時檢索'FunderSimple'實例? – 2009-09-02 19:59:26
非常多,所以我不必將Funder的所有不需要的外鍵(例如create_by和last_update_by鍵)都加入Staff表中......這反過來又會導致Staff表中多個鍵的更多連接。就合同而言,FunderSimple字段是我唯一需要的字段。我懷疑每次拿到合同都會加入所有這些不需要的表格,這會影響業績。但是,我只是希望有一種方法來解決這個問題,只查詢我需要的東西。 – dotjoe 2009-09-02 20:15:29