package com.hibernate.rqq;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
@Entity
public class Husband {
privateint id;
privateString name;
privateWife wife;
@Id
@GeneratedValue
publicint getId() {
returnid;
}
publicString getName() {
returnname;
}
@OneToOne(optional=false)
@PrimaryKeyJoinColumn
publicWife getWife() {
returnwife;
}
publicvoid setWife(Wife wife) {
this.wife= wife;
}
publicvoid setId(int id) {
this.id= id;
}
publicvoid setName(String name) {
this.name= name;
}
}
package com.hibernate.rqq;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Wife {
privateint id;
private Stringname;
@Id
@GeneratedValue
public int getId() {
returnid;
}
publicString getName() {
returnname;
}
publicvoid setId(int id) {
this.id= id;
}
publicvoid setName(String name) {
this.name= name;
}
}