這裏是父類Enterprise。它有僱主,其中之一是企業總裁。Hibernate映射:子對象屬性上的OneToMany和OneToOne
@Entity
class Enterprise
{
// fields
@OneToMany
public List<Employee> getEmployers()
// implementation
@OneToOne
public Employee getPresident()
// implementation
}
這裏是孩子Employee類。它只有關於他工作的企業的信息。但問題是我應該使用哪種關聯?
@Entity
class Employee
{
// fields
// what association should I use?
public Enterprise getEnterprise()
// implementation
}
爲什麼不OneToOne? –
@Nathan - 因爲在一個企業裏可以有很多員工,而不僅僅是一個。 –