首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

hibernate 一对一双向联系关系_外键

2013-12-13 
hibernate 一对一双向关联_外键这种情况是多对一的特例,即外键不准重复。??1.单向一对一Person类:package c

hibernate 一对一双向关联_外键

这种情况是多对一的特例,即外键不准重复。

?

?

1.单向一对一

Person类:

package com.bjpowernode.hibernate.domain;public class Person {private int id;private String name;private IdCard idCard;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getId() {return id;}public void setId(int id) {this.id = id;}public IdCard getIdCard() {return idCard;}public void setIdCard(IdCard idCard) {this.idCard = idCard;}}

?

Person配置文件:

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.bjpowernode.hibernate.domain.Person" table="t_person"><id name="id"><generator unique="true"/></class></hibernate-mapping>

?

?

?

?

?

IdCard类:

package com.bjpowernode.hibernate.domain;public class IdCard {private int id;private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getId() {return id;}public void setId(int id) {this.id = id;}/*public Set getStudents() {return students;}public void setStudents(Set students) {this.students = students;}*/}

?

IdCard配置文件:

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.bjpowernode.hibernate.domain.IdCard" table="t_idcard"><id name="id"><generator name="code">package com.bjpowernode.hibernate.domain;public class IdCard {private int id;private String name;private Person person;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getId() {return id;}public void setId(int id) {this.id = id;}/*public Set getStudents() {return students;}public void setStudents(Set students) {this.students = students;}*/public Person getPerson() {return person;}public void setPerson(Person person) {this.person = person;}}

?

?

IdCard配置文件:

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="com.bjpowernode.hibernate.domain.IdCard" table="t_idcard"><id name="id"><generator property-ref="idCard"/></class></hibernate-mapping>

?

至此,双向一对一,外键策略完成。

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

热点排行