2010-02-12 36 views
1

對不起,因爲我的母語不是我的母語,所以請提前打擾我的英語。
如同在這個例子中: http://www.xylax.net/hibernate/manytomany.html


但我有在表foo杆2點的屬性其不是伯或外鍵的一部分:一個布爾型(A)&一個串(B)。 我知道如何映射它沒有屬性,但不是在這種情況下。

我還沒有在文檔中找到答案。

我需要知道如何繪製它&什麼樣的集合我必須在我的班Foo中聲明。

多對多與屬性的關係:如何?

在此先感謝您的回答。

我真的非常感謝你給的時間。

+0

您可以發佈您的答案以幫助其他用戶尋找相同的解決方案嗎? – 2010-02-12 10:14:34

回答

1

我想你需要創建第三個類來保存這些屬性

1

引述Hibernate用戶常見問題的I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?條目:

使用複合元素的 關聯表建模。例如,給定 以下關聯表:

create table relationship ( 
    fk_of_foo bigint not null, 
    fk_of_bar bigint not null, 
    multiplicity smallint, 
    created date) 

你可以使用這個集合的映射 (映射爲類Foo內):

<set name="relationship"> 
    <key column="fk_of_foo"/> 
    <composite-element class="Relationship"> 
     <property name="multiplicity" type="short" not-null="true"/> 
     <property name="created" type="date" not-null="true"/> 
     <many-to-one name="bar" class="Bar" not-null="true"/> 
    </composite-element> 
</set> 

您也可以與 替代使用<idbag>鍵列爲 收集表。這將允許你 有空列。

的另一種方法是簡單地 關聯表映射爲正常 實體類具有兩個雙向 一個一對多關聯。

相關問題