请假表:
public void setEmployeeName(java.lang.String employeeName) {
this.employeeName = employeeName;
}
private EmployeeEntity employeeEntity;
@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER,optional=true)
public EmployeeEntity getEmployeeEntity() {
return employeeEntity;
}
public void setEmployeeEntity(EmployeeEntity employeeEntity) {
this.employeeEntity = employeeEntity;
}
@Transient
public java.lang.String getEmployeeName() {
if(employeeEntity != null){
return employeeEntity.getEmployeeName();
}else{
return "";
}
}
public void setEmployeeName(java.lang.String employeeName) {
this.employeeName = employeeName;
}
员工表:
@OneToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.LAZY, targetEntity = AbsenceEntity.class, mappedBy = "employeeEntity")
public List<AbsenceEntity> getAbsenceList() {
return absenceList;
}
public void setAbsenceList(List<AbsenceEntity> absenceList) {
this.absenceList = absenceList;
}
如果请假表里面找不到员工表信息,就会出错,之所以找不到,可能是数据在进入请假表时候,没有产生关联关系
比如我先在请假表里面产生了数据,后来才配置一对多关系,所以先前的数据时没有被关系维护的,所以
也就找不到员工表信息了,所以获取员工名称就会出现问题,而红色部分是我后来添加的,判断如果是null的情况,
这样,就算找不到员工信息,也不会导致请假表数据显示不出来了