037:hibernate一对一双向外键关联(xml)
来源:互联网 发布:桥梁工程量计算软件 编辑:程序博客网 时间:2024/05/21 08:04
以Student.java和StuIdCard.java为例:
1、在Student.java中加:
private StuIdCard stuIdCard;
在StudIdCard .java中加:
private Student student;
package com.bjsxt.hibernate;public class Student {private int id;private String name;private int age;private String sex;private boolean good;private StuIdCard stuIdCard;public StuIdCard getStuIdCard() {return stuIdCard;}public void setStuIdCard(StuIdCard stuIdCard) {this.stuIdCard = stuIdCard;}public boolean isGood() {return good;}public void setGood(boolean good) {this.good = good;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}}
package com.bjsxt.hibernate;public class StuIdCard {private int id;private String num;private Student student;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getNum() {return num;}public void setNum(String num) {this.num = num;}public Student getStudent() {return student;}public void setStudent(Student student) {this.student = student;}}
2、在Student.hbm.xml中加入:
<one-to-one name="stuIdCard" property-ref="student"></one-to-one>
总的:
<hibernate-mapping><class name="com.bjsxt.hibernate.Student" dynamic-update="true"><id name="id"><generator class="native"></generator></id><property name="name"></property><property name="age" /><property name="sex" /><property name="good" type="yes_no"></property><one-to-one name="stuIdCard" property-ref="student"></one-to-one> </class></hibernate-mapping>
在StuIdCard.hbm.xml中加入:
<many-to-one name="student" column="studentId" unique="true"></many-to-one>
总的:
<hibernate-mapping><class name="com.bjsxt.hibernate.StuIdCard"><id name="id"><generator class="native"></generator></id><property name="num"/><many-to-one name="student" column="studentId" unique="true"></many-to-one> </class></hibernate-mapping>
2、在hibernate.cfg.xml中加入:
<mapping resource="com/bjsxt/hibernate/Student.hbm.xml"/> <mapping resource="com/bjsxt/hibernate/StuIdCard.hbm.xml"/>
0 0
- 037:hibernate一对一双向外键关联(xml)
- 037:hibernate一对一双向外键关联(Annotation)
- 【hibernate框架】一对一双向外键关联(XML实现)
- hibernate一对一双向外键关联
- hibernate一对一双向外键关联_Annotation
- hibernate一对一双向外键关联_XML
- hibernate Annotation一对一双向外键关联
- hibernate一对一双向外键关联
- hibernate学习:一对一双向外键关联
- hibernate一对一双向外键关联
- Hibernate:一对一双向外键关联
- Hibernate关系映射级别注解(一对一双向外键关联、一对一双向外键联合主键)
- Hibernate关系映射(2)_一对一双向外键关联
- Hibernate学习笔记_07_一对一双向外键关联
- 【hibernate框架】一对一双向外键关联(Annotation实现)
- Hibernate关系映射(二)一对一双向外键关联@OneToOne Annotation方式
- Hibernate_一对一双向外键关联
- hibernate annotation 之 一对多、多对一双向外键关联
- 浅析信息安全与社会关系的映射关系
- LinearLayout 动态添加子Button,并自动换行
- 已序集合求交运算和求差运算
- 接下来的两年你可能需要这五种语言!
- android中资产文件的拷贝
- 037:hibernate一对一双向外键关联(xml)
- slab 着色的理解
- error C2664: “MessageBoxW”解决方案
- maven 教程一 入门
- Linux 系统中的 SNMP Trap
- <Git>Windows7的Git Bash设置密码缓存 (cache credential)
- TortoiseSVN使用简介
- xcode 终端找不到路径换路径方法
- 大数据挖掘方法介绍