husband表结构:
[img]http://dl.iteye.com/upload/attachment/592515/86178b16-ae58-3f62-8dc1-e5b32e0d018e.jpg[/img]
wife表结构:
[img]http://dl.iteye.com/upload/attachment/592517/43601158-5c3c-34d4-aaf3-dacae75c5771.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/592515/86178b16-ae58-3f62-8dc1-e5b32e0d018e.jpg[/img]
wife表结构:
[img]http://dl.iteye.com/upload/attachment/592517/43601158-5c3c-34d4-aaf3-dacae75c5771.jpg[/img]
package com.bjsxt.hibernate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
@Entity
public class Husband {
private int id;
private String name;
private Wife wife;
@Id
@GeneratedValue
public int getId() {
return id;
}
public String getName() {
return name;
}
@OneToOne
@PrimaryKeyJoinColumn
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.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
@Entity
public class Wife {
private int id;
private String name;
private Husband husband;
@OneToOne
@PrimaryKeyJoinColumn
public Husband getHusband() {
return husband;
}
public void setHusband(Husband husband) {
this.husband = husband;
}
@Id
@GeneratedValue
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;
}
}