- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Hibernate表的对应关系
Hibernate表的对应关系
重点:多对多关系
难点:多对多关系
课程类型:理论
教学内容:
一、一对一的关系
?假设有2个表:person 和idcard
? 在person和idcard表的pojo 类里面分别设置另一个表的属性:private Person person;(Idcard类里面声明person类) private Idcard idcard (Person类里面声明)
?在配置文件中为如下表示:主表person:? one-to-one name=idcard class=com.guoc.vo.Idcard cascade=all???????/one-to-one
?副表idcard:副表的id根据外键即主表的idgenerator class=foreign???????? param name=propertyperson/param??????????? /generator
one-to-one name=person class=com.guoc.vo.Person??????? ?constrained=true
??????? /one-to-one
在操作的时候:Person person = new Person();??person.setPid(idcardForm.getString(pid));
ic.setPerson(person);
二、一对多
假设有2个表 部门dept(主表)和人员emp(从表)在主表的pojo类里面声明:private Set emps;
在从表的pojo类里面声明:private Dept dept;
(主表)配置文件中的写法为:
?set name=emps table=emp inverse=true cascade=all??????????? key??????????????? column name=deptno length=32 /??????????? /key??????????? one-to-many class=com.guoc.vo.Emp / /set
?(从表)配置文件中的写法为:
? many-to-one name=dept class=com.guoc.vo.Dept??????????? column name=deptno length=32 /? /many-to-one
操作的时候为:Dept dept=new Dept();??dept.setDeptno(empForm.getDeptno());??emp.setDept(dept);
三、多对多
假设有2个表:student 和course 有多对多的关系,那必须得有另一个中间表(student_course)存储他们之间的对应关系
这样的话 就转为2个一对多的关系了
student_course的表结构为:
create table student_course(
?? cid int not null,?? sid int not null,??? foreign key (sid) references student(sid),?? foreign key (cid) references course(cid)
);
在student 和course的pojo 类里面都得为对应类声明,分别为:
?private Set coures;
private Set students;
在student的配置文件中表示为:set name=coures inverse=true cascade=all table=student_course?????????key??????????????? column name=sid not-null=true /??????????? /key??????????? many-to-many class=com.guoc.vo.Course column=cid/??????? /set
在course的配置文件中表示为:set name=students cascade=all inverse=true table=student_course??????????? key??????????????? column name=cid not-null=true /??????????? /key??????????? many-to-many class=com.guoc.vo.Student column=sid/??????? /set
这样写好后,虽然能对student里的courses集合进行操作,但是集合里的数据一直为空,因为他
您可能关注的文档
- Dynamics of FD networks the role of bound states.pdf
- Dynamics Of Hadronization From Nuclear Semi Inclusive Deep Inelastic Scattering.pdf
- Dynamics of interacting neural networks.pdf
- Dynamics of LongLiving Excitons in Tunable Potential Landscapes.pdf
- Dynamics of Nucleation in the Ising Model.pdf
- Dynamics of onedimensional Bose liquids Andreevlike reflection at Yjunctions and absence.pdf
- Dynamics of Open Bosonic Quantum Systems in Coherent State Representation.pdf
- Dynamics of strangeness production in the near threshold nucleonnucleon collisions.pdf
- Dynamics of the BornInfeld dyons.pdf
- Dynamics of TwoLevel System Interacting with Random Classical Field.pdf
- History of Theory and Analysis in Applied Linguistics.ppt
- HIV初筛实验室样品采集和处理程序.doc
- How Should Research Contribute to Instructional Improvement The Case of Lesson Study.pdf
- How it Works A Field Study of NonTechnical Users Interacting with an Intelligent System.pdf
- How to act as a good leader(蝇王分析).doc
- HPLC_ICP_MS在环境样品的痕量元素形态分析中的应用.pdf
- HPLC测定奶粉中三聚氰胺.doc
- HPLC法测定蒲黄中总黄酮的含量.pdf
- HR发展方向.doc
- HS—SPMEGCMS联用测定孟买蓝宝石金酒中的香气成分.pdf
最近下载
- 江西财经大学西方经济学复习重点.docx VIP
- 刑事被害人心理损害的范围 (1).pptx VIP
- 某集团2021年人才盘点项目方案(项目建议书).pptx VIP
- 党委书记讲党课+讲稿—深入学习贯彻党的二十届三中全会精神-聚焦四个持之以恒,驱动企业高质量发展.pptx VIP
- 分裂型人格障碍的案例分析.doc VIP
- GB51445-2021 锑冶炼厂工艺设计标准.pdf VIP
- DL T 868-2014 焊接工艺评定规程 .docx VIP
- 第十届全国走美杯三年级初赛竞赛数学试卷答案.docx VIP
- 学校膳食监督家长委员会成立大会上,校长发言:从餐桌开始,家校合力为孩子成长食堂 “加营养”.docx VIP
- 《拍手歌》优秀课件.ppt VIP
文档评论(0)