我正在使用Spring Boot,Data,JPA Hibernate。我面临的问题与-THIS
有关当我尝试遵循@Maciej的“选项1”并执行-
UserDepartmentRoleLink udr1 = new UserDepartmentRoleLink();
System.out.println("\nAdding UserDepartmentRole....");
udr1.setUser(user1);
udr1.setDepartment(department1);
udr1.setRole(role1);
uprRepository.save(udr1);
UserDepartmentRoleLink udr2 = new UserDepartmentRoleLink();
System.out.println("\nAdding UserDepartmentRole....");
udr2.setUser(user1);
udr2.setDepartment(department1);
udr2.setRole(role1);
uprRepository.save(udr2);
我最终在UserDepartmentRoleLink表(mysql)中有重复的条目。不会抛出异常。!
我在这里怎么了?
这是预期的行为吗?
如何避免重复值?