我有一個實體,我想通過Hibernate持久化(3.2) EntityBean有一個列,指示另一個值實體bean應解組:表中的Hibernate Reference列指示如何在同一個表中的不同列中解組一個屬性
<class name="ServiceAttributeValue" table="service_attribute_value">
<cache usage="nonstrict-read-write"/>
<id name="id" column="id" type="int-long">
<generator class="native"/>
</id>
<property name="serviceAttribute" type="service-attribute" column="service_attribute" not-null="true" />
<!-- order is important here -->
<property name="value" type="attribute-value" not-null="true">
<column name="service_attribute" />
<column name="id_value"/>
<column name="enum_value"/>
<column name="string_value"/>
<column name="int_value"/>
<column name="boolean_value"/>
<column name="double_value"/>
</property>
</class>
的「service_attribute」列指示尋找它的「值」屬性欄的時候解組值的和,更重要的是,到底是什麼類型的值應該是,例如,如果要讀取enum_value,則爲Enum類;如果要讀取id_value,則爲Bean的類型。
value屬性使用自定義CompositeUserType做解組,並在此我想不過來引用service_attribute列(雖然不寫入),當我嘗試這樣做,我得到以下錯誤:
org.hibernate.MappingException: Repeated column in mapping for entity: com.precurse.apps.rank.model.service.ServiceAttributeValue column: service_attribute (should be mapped with insert="false" update="false")
但是在複合屬性的定義中,這些xml屬性沒有被定義(只在一個正常的屬性中)。
有沒有人知道克服這種方式,或者如果有更好的解決方案這個問題。
如果您需要了解更多信息,請讓我知道,
乾杯 西蒙
Hi Hsiu, 感謝您回覆帖子。我想要做的是*避免*你有一個繼承層次結構。 每個服務*理論上可以是主服務類的一個子類,所以我可以有一個保險服務,金融服務,園藝服務等。 因爲他們有這麼多可能的服務,並且因爲(在這個領域至少)他們是非常簡單的名稱值類型結構我試圖避免有這樣的結構,因爲 a。它需要編程開銷 b。服務的行爲真的非常有限,而且只是數據持有者。 – 2010-02-12 01:51:43