@Entity
class Employee {
@Column
private UUID id;
@Column
private String firstName;
@Column
private String lastName;
}
和
@Entity
class Department {
@Column
private UUID id;
@Column
private List<Employee> employees;
}
- 我想要一个单独的表,该表与DepartmentEmployee等员工具有OneToMany关系
--------------------------
departmentId | EmployeeId
--------------------------
1 | 1 |
1 | 2 |
1 | 3 |
2 | 5 |
--------------------------
- 我想确保有一个
uniqueConstraint
onDepartment.id
和Employee.id
我如何做到这一点JPA
?