问题描述
我这里有2节课
- 部门(did,dname)
- 员工[身份证,姓名,地址,部门(did)] 这里部门列是部门表中的外键。
- 一个员工只有一个部门
- 员工表将外键作为部门映射到部门的部门
- 部门不应有重复的条目
当我将数据插入到员工表中时,我也将数据插入到部门表中,我不想要那个。
问题是当我将数据插入到employee表中时,我应该在雇员表中插入“ did”'',而不要在部门表中插入任何内容。即,如果要在employee表中插入的数据(dname)已经存在于department表中,那我在控制台中应该不会出现任何错误并在department表中进行更新。
在以下类和映射策略中要进行哪些更改
Department.java
@Entity
public class Department1
{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int did;
@Column(unique=true)
private String dname;
public int getDid() {
return did;
}
public void setDid(int did) {
this.did = did;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
Employee.java
@Entity
public class Employe1
{
@Id
@GeneratedValue
private int id;
private String name;
@ManyToOne
@JoinColumn(name="department",referencedColumnName="did")
private Department1 department;
private String dob;
private long phone;
private String email;
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;
}
public Department1 getDepartment() {
return department;
}
public void setDepartment(Department1 department) {
this.department = department;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public long getPhone() {
return phone;
}
public void setPhone(long phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)