我的项目的目的是要有管理员/经理/雇员/客户。登录后,取决于角色的用户将具有以下功能:
问题是,我坚持了几个星期是在更新任何用户信息时,它会自动从数据库中删除该用户角色。这样会将他们从网络应用中删除。
我已经进行了一些研究,试图找出答案,但是没有找到一个可靠的答案。任何帮助,将不胜感激,谢谢!
Employee.java
b
EmployeeController.java-
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "employee_roles",
joinColumns = @JoinColumn(name = "employee_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
private Collection<Role> roles;
EmployeeDaoImpl.java-
@PostMapping("/saveEmployee")
public String saveEmployee(@ModelAttribute("employee") Employee theEmployee) {
employeeService.saveEmployee(theEmployee);
return "redirect:/employee/list";
}
日志-
@Override
public void saveEmployee(Employee theEmployee) {
// get current hibernate session
Session currentSession = sessionFactory.getCurrentSession();
// save Employee
currentSession.update(theEmployee);
}
编辑:
Role.java
Hibernate: update employee set address=?, email=?, first_name=?, last_name=?, password=?, phone_number=?, username=?, zipcode=? where id=?
Hibernate: delete from employee_roles where employee_id=?
答案 0 :(得分:0)
您可以将以下代码添加到Role类中:
@ManyToMany(mappedBy="roles")
private Collection<Employee> employees;