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

8.hibernate一对一双向外键联系关系,jpa映射

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

8.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;import javax.persistence.OneToOne;@Entitypublic class Wife {private int id;private String name;private Husband husband;@OneToOne(mappedBy="wife")//关联关系由Husband的wife确定public Husband getHusband() {return husband;}public void setHusband(Husband husband) {this.husband = husband;}@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;}}

热点排行