I have 2 tables : Employee and Department (many to one relationship)
My pojos look like this:
@Entity
@Table(name = "employee")
class Employee {
@Id
private String employeeId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinTable(name = "department", joinColumns = @JoinColumn(name = "university_id"))
private Department department;
}
@Entity
@Table(name = "department")
class Department {
@Id
private String deptId;
private String universityId;
}
所以基本上当Employee对象加载/获取时,它应该使用unique_id(可能不是唯一的)来加载它的数据成员Department,而不是它的主键dept_id。如何使用注释来做到这一点?
我是 hibernate 的新手。请让我知道我需要做什么。总结问题:如何使用除主键或来自另一个 POJO 的唯一列之外的任何列加载对象?