I tried to make one-to-one relationship. But I get error:
AnnotationException Referenced property not a (One|Many)ToOne
on
com.student.information.service.Department.departmentId in mappedBy of com.student.information.service.DepartmentHead.department
Both the entities are almost identical. Department can exists with out department head.
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;
}
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;
}
Caused by: org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne:
can someone please point me in the right direction about what mistake am I making. I am struggling from past 2 days and not able to figure out the solution for the issue. Thanks in advance for help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…