@Entity
@DiscriminatorValue("員工")
public class Employ extends Person4 {
private String title;
private double salary;
@ManyToOne(cascade=CascadeType.ALL,targetEntity=Manger.class)
@JoinColumn(name="manger_id",nullable=true)
private Manger manger;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public Manger getManger() {
return manger;
}
public void setManger(Manger manger) {
this.manger = manger;
}
}
@Entity
@DiscriminatorValue("經理")
public class Manger extends Employ {
private String department;
@OneToMany(cascade=CascadeType.ALL
, mappedBy="manger" , targetEntity=Employ.class)
private Set<Employ> employs=new HashSet<Employ>();
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Set<Employ> getEmploys() {
return employs;
}
public void setEmploys(Set<Employ> employs) {
this.employs = employs;
}
}
已解決,由於是使用父類映射所以雖然在manger類中沒有指定主鍵id但由於是繼承person類,其中有id主鍵,所以外鍵映射能成功