我试图建立一对一的关系.但我得到错误:
AnnotationException Referenced property not a (One|Many)ToOne
on
com.student.information.service.Department.departmentId in mappedBy of com.student.information.service.DepartmentHead.department
Run Code Online (Sandbox Code Playgroud)
两个实体几乎完全相同.部门可以存在部门负责人.
Department.Java
@Entity
@Table(name="department", catalog="student")
public class Department {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer departmentId;
@Column(name="dept_name")
private String departmentName;
@OneToMany(mappedBy="department",cascade = CascadeType.ALL)
private List<Student> student;
@OneToOne(targetEntity=Department.class)
private DepartmentHead departmenthead;
}
Run Code Online (Sandbox Code Playgroud)
DepartmentHead.java
@Entity
@Table(name="departmenthead", catalog = "student")
public class DepartmentHead {
//This is mapped with the department id
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column(name="headname")
private String headName;
@OneToOne(mappedBy = "departmentId",fetch = FetchType.LAZY,cascade=CascadeType.ALL)
@JoinColumn(name="dept_id")
private Department department;
}
Run Code Online (Sandbox Code Playgroud)
引起:org.hibernate.AnnotationException:引用的属性不是(一个|多个)ToOne:
有人可以指出我正确的方向,我正在犯的错误.我在过去的两天里一直在努力,而且无法找到问题的解决方案.在此先感谢您的帮助.