hibernate一對多中,多表中有兩個字段需要引用單表的主鍵,如何寫hbm.xml

hibernate一對多中,多表中有兩個字段需要引用單表的主鍵,如何寫單方中的hbm.xml?

如科目表:Subject(一方)

subjectId
subjectName


前置科目表:PreSubject--存儲學習某科目前必須先學某個科目的信息(多方)

id
subjectId(科目id,引用的科目表的id)
preSubjectId(科目的前置科目id,仍然引用的科目表的id)

前置科目映射文件:PreSubject.hbm.xml
[code]
<hibernate-mapping package="db">
<class
name="PreSubject"
table="pre_subject"
>
<id
name="id"
type="integer"
column="id"
>
<generator class="increment"/>
</id>

<many-to-one name="subject" class="db.Subject" column="subject_id"/>

<many-to-one name="preSubject" class="db.Subject" column="pre_subject_id"/>

</class>
</hibernate-mapping>

[/code]

[b] [color=red] 問題就在下面這個hbm文件,如何寫映射中這個set呢?請指點,謝謝![/color] [/b]

科目映射文件:Subject.hbm.xml

[code]

<hibernate-mapping package="db">
<class
name="Subject"
table="subject"
>

<id
name="id"
type="integer"
column="subject_id"
>
<generator class="increment"/>
</id>

<set
name="preSubjects"
lazy="false"
cascade = "all"
inverse="true"
>
<key column="subject_id"/>
<one-to-many class="db.PreSubject"/>
</set>

</class>
</hibernate-mapping>
[/code]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章