标签:name class reference eid and this embed idc dcl
package com.bjsxt.hibernate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToOne;
public class Wife {
private String wifename;
private String age;
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getWifename() {
return wifename;
}
public void setWifename(String wifename) {
this.wifename = wifename;
}
}
······················································
package com.bjsxt.hibernate;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
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;
}
//@JoinColumn(name="wife_id")
// @OneToOne
// @JoinColumns(
// {
// @JoinColumn(name="wifeId",referencedColumnName="id"),
// @JoinColumn(name="wifeName",referencedColumnName="name")
// }
//
// )
@Embedded //不能写在变量上
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;
}
}
标签:name class reference eid and this embed idc dcl
原文地址:http://www.cnblogs.com/lize1215/p/7641065.html