




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、hibernate關(guān)聯(lián)關(guān)系映射配置2一、一對一單向外鍵關(guān)聯(lián):21.1目錄結(jié)構(gòu)21.2 annotation方式21.3 xml方式41.4 hibernate配置文件7二、一對一雙向外鍵關(guān)聯(lián)72.1 annotation方式72.2 xml方式9三、一對一單向主鍵關(guān)聯(lián)(不重要)123.1 annotation方式123.2 xml方式14四、一對一雙向主鍵關(guān)聯(lián)(不重要)164.1 annotation方式163.2 xml方式19五、組件映射215.1 annotation方式215.2 xml方式23六、多對一單向關(guān)聯(lián)256.1 annotation方式256.2 xml方式27七、一對多單
2、向關(guān)聯(lián)297.1 annotation方式297.2 xml方式31八、一對多、多對一雙向關(guān)聯(lián)348.1 annotation方式348.2 xml方式36九、多對多單向關(guān)聯(lián)398.1 annotation方式398.2 xml方式41十、多對多雙向關(guān)聯(lián)448.1 annotation方式448.2 xml方式46hibernate關(guān)聯(lián)關(guān)系映射配置一、 一對一單向外鍵關(guān)聯(lián):1.1目錄結(jié)構(gòu)圖1-1 目錄結(jié)構(gòu)圖1.2 annotation方式1.2.1 類圖圖1-2 類關(guān)聯(lián)關(guān)系圖1.2.2數(shù)據(jù)庫表結(jié)構(gòu)圖1-3數(shù)據(jù)庫表結(jié)構(gòu)圖1.2.3 實(shí)體類package com.rongqq.hibernate3
3、.annotation.entity;import java.math.bigdecimal;import javax.persistence.column;import javax.persistence.entity;import javax.persistence.generatedvalue;import javax.persistence.generationtype;import javax.persistence.id;import javax.persistence.onetoone;import javax.persistence.sequencegenerator;enti
4、ty(name=h_husband_)sequencegenerator(name=husband_seq_gene, sequencename=husband_seq, allocationsize=1)public class husband private bigdecimal id;private string name;private wife wife;idcolumn(precision=4, scale=0)generatedvalue(strategy=generationtype.sequence, generator=husband_seq_gene)public big
5、decimal getid() return id;column(length=30)public string getname() return name;onetoone/joincolumn(name=wife_id)/不寫也沒問題,自動(dòng)生成的字段也叫wife_idpublic wife getwife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public void setwife(wife wife) thi
6、s.wife = wife;package com.rongqq.hibernate3.annotation.entity;import java.math.bigdecimal;import javax.persistence.column;import javax.persistence.entity;import javax.persistence.generatedvalue;import javax.persistence.generationtype;import javax.persistence.id;import javax.persistence.sequencegener
7、ator;entity(name=h_wife_)sequencegenerator(name=wife_seq_gene, sequencename=wife_seq)public class wife private bigdecimal id;private string name;idcolumn(precision=4)generatedvalue(strategy=generationtype.sequence, generator=wife_seq_gene)public bigdecimal getid() return id;public void setid(bigdeci
8、mal id) this.id = id;column(length=30)public string getname() return name;public void setname(string name) = name;1.3 xml方式1.3.1 類圖圖1-4 類關(guān)聯(lián)關(guān)系圖1.3.2 數(shù)據(jù)庫表結(jié)構(gòu)圖1-5數(shù)據(jù)庫表結(jié)構(gòu)圖1.3.3 實(shí)體類package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;public class xml_husband private bigdecimal id;
9、private string name;private xml_wife wife;public bigdecimal getid() return id;public string getname() return name;public xml_wife getwife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public void setwife(xml_wife wife) this.wife = wife;
10、package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;public class xml_wife private bigdecimal id;private string name;public bigdecimal getid() return id;public void setid(bigdecimal id) this.id = id;public string getname() return name;public void setname(string name) = name
11、;1.3.4 對象關(guān)系映射文件h_student_seq_xml h_student_seq_xml 1.4 hibernate配置文件oracle.jdbc.driver.oracledriverjdbc:oracle:thin::1521:silencecnusercn8303061threadorg.hibernate.cache.nocacheprovidertruetrueorg.hibernate.dialect.oracle9dialect!-update-二、一對一雙向外鍵關(guān)聯(lián)2.1 annotation方式2.1.1 類圖圖2-1類關(guān)聯(lián)關(guān)系圖2.1.2 數(shù)據(jù)
12、庫結(jié)構(gòu)圖圖2-2數(shù)據(jù)庫表結(jié)構(gòu)圖2.1.3 實(shí)體類entity(name=h_husband_)sequencegenerator(name=husband_seq_gene, sequencename=husband_seq, allocationsize=1)public class husband private bigdecimal id;private string name;private wife wife;idcolumn(precision=4, scale=0)generatedvalue(strategy=generationtype.sequence, generator
13、=husband_seq_gene)public bigdecimal getid() return id;column(length=30)public string getname() return name;onetoone/joincolumn(name=wife_id)/不寫也沒問題,自動(dòng)生成的字段也叫wife_idpublic wife getwife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public
14、 void setwife(wife wife) this.wife = wife;entity(name=h_wife_)sequencegenerator(name=wife_seq_gene, sequencename=wife_seq)public class wife private bigdecimal id;private string name;private husband husband;idcolumn(precision=4)generatedvalue(strategy=generationtype.sequence, generator=wife_seq_gene)
15、public bigdecimal getid() return id;public void setid(bigdecimal id) this.id = id;column(length=30)public string getname() return name;public void setname(string name) = name;onetoone(mappedby=wife)public husband gethusband() return husband;public void sethusband(husband husband) this.husb
16、and = husband;2.2 xml方式2.2.1 類圖圖2-3 類關(guān)聯(lián)關(guān)系圖2.2.2 數(shù)據(jù)庫結(jié)構(gòu)圖2.2.3 實(shí)體類package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;public class xml_husband private bigdecimal id;private string name;private xml_wife wife;public bigdecimal getid() return id;public string getname() return name;public
17、xml_wife getwife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public void setwife(xml_wife wife) this.wife = wife;package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;public class xml_wife private bigdecimal id;private
18、string name;private xml_husband husband;public bigdecimal getid() return id;public void setid(bigdecimal id) this.id = id;public string getname() return name;public void setname(string name) = name;public xml_husband gethusband() return husband;public void sethusband(xml_husband husband) t
19、his.husband = husband;2.2.4 對象關(guān)系映射文件h_student_seq_xml h_student_seq_xml 三、一對一單向主鍵關(guān)聯(lián)(不重要)3.1 annotation方式3.1.1 類圖圖3-1 類關(guān)聯(lián)關(guān)系圖3.1.2 數(shù)據(jù)庫表結(jié)構(gòu)圖3-2 數(shù)據(jù)庫表結(jié)構(gòu)圖3.1.3 實(shí)體類package com.rongqq.hibernate3.annotation.entity;import java.math.bigdecimal;import javax.persistence.column;import javax.persistence.entity;impo
20、rt javax.persistence.generatedvalue;import javax.persistence.generationtype;import javax.persistence.id;import javax.persistence.onetoone;import javax.persistence.primarykeyjoincolumn;import javax.persistence.sequencegenerator;entity(name=h_husband_)sequencegenerator(name=husband_seq_gene, sequencen
21、ame=husband_seq, allocationsize=1)public class husband private bigdecimal id;private string name;private wife wife;idcolumn(precision=4, scale=0)generatedvalue(strategy=generationtype.sequence, generator=husband_seq_gene)public bigdecimal getid() return id;column(length=30)public string getname() re
22、turn name;onetooneprimarykeyjoincolumnpublic wife getwife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public void setwife(wife wife) this.wife = wife;package com.rongqq.hibernate3.annotation.entity;import java.math.bigdecimal;import j
23、avax.persistence.column;import javax.persistence.entity;import javax.persistence.generatedvalue;import javax.persistence.generationtype;import javax.persistence.id;import javax.persistence.sequencegenerator;entity(name=h_wife_)sequencegenerator(name=wife_seq_gene, sequencename=wife_seq)public class
24、wife private bigdecimal id;private string name;idcolumn(precision=4)generatedvalue(strategy=generationtype.sequence, generator=wife_seq_gene)public bigdecimal getid() return id;public void setid(bigdecimal id) this.id = id;column(length=30)public string getname() return name;public void setname(stri
25、ng name) = name;注:只生成了表,但是沒有外鍵約束,具體實(shí)現(xiàn)還需要查找3.2 xml方式3.2.1 類圖圖3-3 類關(guān)聯(lián)關(guān)系圖3.2.2 數(shù)據(jù)庫表結(jié)構(gòu)圖3-4 數(shù)據(jù)庫表結(jié)構(gòu)圖3.2.3 實(shí)體類package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;public class xml_husband private bigdecimal id;private string name;private xml_wife wife;public bigdecimal getid() ret
26、urn id;public string getname() return name;public xml_wife getwife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public void setwife(xml_wife wife) this.wife = wife;package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;im
27、port com.rongqq.hibernate3.annotation.entity.husband;public class xml_wife private bigdecimal id;private string name;public bigdecimal getid() return id;public void setid(bigdecimal id) this.id = id;public string getname() return name;public void setname(string name) = name;3.2.4 對象映射文件wif
28、e h_student_seq_xml 四、一對一雙向主鍵關(guān)聯(lián)(不重要)4.1 annotation方式4.1.1 類圖圖4-1 類關(guān)聯(lián)關(guān)系圖4.1.2 數(shù)據(jù)庫表結(jié)構(gòu)圖4-2 數(shù)據(jù)庫表結(jié)構(gòu)圖4.1.3 實(shí)體類package com.rongqq.hibernate3.annotation.entity;import java.math.bigdecimal;import javax.persistence.column;import javax.persistence.entity;import javax.persistence.generatedvalue;import javax.per
29、sistence.generationtype;import javax.persistence.id;import javax.persistence.onetoone;import javax.persistence.primarykeyjoincolumn;import javax.persistence.sequencegenerator;entity(name=h_husband_)sequencegenerator(name=husband_seq_gene, sequencename=husband_seq, allocationsize=1)public class husba
30、nd private bigdecimal id;private string name;private wife wife;idcolumn(precision=4, scale=0)generatedvalue(strategy=generationtype.sequence, generator=husband_seq_gene)public bigdecimal getid() return id;column(length=30)public string getname() return name;onetooneprimarykeyjoincolumnpublic wife ge
31、twife() return wife;public void setid(bigdecimal id) this.id = id;public void setname(string name) = name;public void setwife(wife wife) this.wife = wife;package com.rongqq.hibernate3.annotation.entity;import java.math.bigdecimal;import javax.persistence.column;import javax.persistence.ent
32、ity;import javax.persistence.generatedvalue;import javax.persistence.generationtype;import javax.persistence.id;import javax.persistence.onetoone;import javax.persistence.primarykeyjoincolumn;import javax.persistence.sequencegenerator;entity(name=h_wife_)sequencegenerator(name=wife_seq_gene, sequenc
33、ename=wife_seq)public class wife private bigdecimal id;private string name;private husband husband;idcolumn(precision=4)generatedvalue(strategy=generationtype.sequence, generator=wife_seq_gene)public bigdecimal getid() return id;public void setid(bigdecimal id) this.id = id;column(length=30)public s
34、tring getname() return name;public void setname(string name) = name;onetooneprimarykeyjoincolumnpublic husband gethusband() return husband;public void sethusband(husband husband) this.husband = husband;注:同樣不產(chǎn)生關(guān)聯(lián)關(guān)系,具體實(shí)現(xiàn)待查3.2 xml方式4.2.1 類圖圖4-3 類關(guān)聯(lián)關(guān)系圖4.2.2 數(shù)據(jù)庫表結(jié)構(gòu)圖4-4 數(shù)據(jù)庫表結(jié)構(gòu)圖4.2.3 實(shí)體類package com.rongqq.hibernate3.xml.entity;import java.math.bigdecimal;public class xml_husband private bigdecimal id;private string name;private xml_wife wife;public bigdecimal getid() return id;public string getname() return name;public xml_wife getwife() return wife
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年執(zhí)業(yè)醫(yī)師考試現(xiàn)場技巧試題及答案
- 2025年藥師考試中的邏輯推理題分析試題及答案
- 2025年大學(xué)語文復(fù)習(xí)要點(diǎn)及試題及答案
- 行政法學(xué)的課程內(nèi)容更新問題試題及答案
- 2025年護(hù)師考試的回顧與試題及答案
- 行政管理應(yīng)試技巧試題與答案
- 2025年行政管理綜合素質(zhì)試題及答案
- 紅十字護(hù)理知識(shí)試題及答案
- 如何分析中國文化的變遷與現(xiàn)代化試題及答案
- 行政法學(xué)研究重要性試題及答案分析
- 2025年視覺傳達(dá)設(shè)計(jì)專業(yè)能力考試試題及答案
- 《家具設(shè)計(jì)》課件
- 任務(wù)一淘米(教學(xué)課件)一年級(jí)下冊勞動(dòng)技術(shù)(人美版)
- 門頭承包合同協(xié)議書范本
- 國有融資擔(dān)保公司筆試真題解析
- 頂管機(jī)租憑合同協(xié)議
- 出納人員面試題及答案
- 中招美育考試試題及答案
- 2025年湖南中考英命題分析及復(fù)習(xí)備考策略指導(dǎo)課件
- 四年級(jí)下冊英語競賽試題
- 《全球教育服務(wù)貿(mào)易》課件
評(píng)論
0/150
提交評(píng)論