我有一个 LazyInitializationException 问题,我不知道如何解决它。
for (Long id : employeeIds)
{
List<ProjectEmployee> projectEmployeeList = projectEmployeeService.findProjectEmployeesWithinDates(id,
startDate, endDate);
// if no data, then continue with next employee
if (projectEmployeeList.isEmpty())
{
continue;
}
gridCreated = true;
Employee employee = projectEmployeeList.get(0).getEmployee();
Label titleLabel = new Label(employee.getPerson().getSurname() + " " + employee.getPerson().getName() + " ["
+ employee.getRole().getHumanizedRole() + "]");
titleLabel.setStyleName("header-bold");
ProjectEmployeePanel projectEmployeePanel = new ProjectEmployeePanel(id, startDate, endDate);
gridPanelsLayout.addComponents(titleLabel, projectEmployeePanel);
}
在问题出现之前,当我打电话给 .getperson=null 但我修复了调用 findProjectEmployeesWithinDates 要求那里接人的问题。但是当我调用“findProjectEmployeesWithinDates”时出现异常。代码 findProjectEmployeesWithinDates:
public List<ProjectEmployee> findProjectEmployeesWithinDates(Long employeeId, LocalDate startDate, LocalDate endDate) {
List<Long> list = new ArrayList<>();
list.add(employeeId);
List<ProjectEmployee> listProjectEmployees = projectEmployeeRepository.findProjectEmployeesWithinDates(list,
LocaleUtils.getDateFromLocalDate(startDate, LocaleUtils.APPLICATION_DEFAULT_ZONE_ID),
LocaleUtils.getDateFromLocalDate(endDate, LocaleUtils.APPLICATION_DEFAULT_ZONE_ID));
for (ProjectEmployee pe : listProjectEmployees)
{
Hibernate.initialize(pe.getEmployee());
Hibernate.initialize(pe.getEmployee().getPerson());
}
return listProjectEmployees;
}
所以使用 debbug 我看到了:
Hibernate.initialize(pe.getEmployee()); ----line 105
Hibernate.initialize(pe.getEmployee().getPerson()); ---line 106
它位于 findProjectEmployeesWithinDates 中 for 循环的第一行,但不在第二行,这就是发生异常的地方。
Smart猫小萌
慕雪6442864
相关分类