可能重複:
JPA OneToOne and ManyToMany between two entitiesJPA OneToOne和一對多的同一實體
我尋找一個解決辦法都無濟於事。我的問題是 我有兩個實體「員工」和「部門」 許多員工屬於一個部門 而一個部門由一個員工領導。 隨時都會出現@OneToOne和@OneToMany錯誤。 這是代碼
public class Department {
@Required
public String deptName;
@OneToMany(mappedBy="dept")
public List<Employee> employees = new ArrayList<Employee>();
@OneToOne
public Employee deptHead = new Employee();
.....
}
public class Employee{
@Required
public String surname;
@Required
public String othernames;
@OneToOne(mappedBy="depthead")
public Department headedBy = new Department();
@ManyToOne
public Department dept = new Department();
...
}
是否可以兼得註釋和工作在同一時間?
什麼是錯誤? – smk
兩個表(或至少兩個表的相關字段)的SQL模式將會很有幫助。 –