首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

6.hibernate一对一单向外键联系关系,jpa映射

2012-07-03 
6.hibernate一对一单向外键关联,jpa映射husband表结构:wife表结构package com.bjsxt.hibernateimport jav

6.hibernate一对一单向外键关联,jpa映射
husband表结构:

wife表结构

package com.bjsxt.hibernate;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.JoinColumn;import javax.persistence.OneToOne;@Entitypublic class Husband {private int id;private String name;private Wife wife;@Id@GeneratedValuepublic int getId() {return id;}public String getName() {return name;}@OneToOne@JoinColumn(name="wifeId")public Wife getWife() {return wife;}public void setId(int id) {this.id = id;}public void setName(String name) {this.name = name;}public void setWife(Wife wife) {this.wife = wife;}}


package com.bjsxt.hibernate;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;@Entitypublic class Wife {private int id;private String name;@Id@GeneratedValuepublic 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;}}

热点排行