您错误地设置了映射。Hibernate抱怨称没有
departmentId可用的字段来建立一对一或多个关系,这是正确的。
您想要这样映射您的值。
Java部门
@Entity@Table(name="department", catalog="student")public class Department { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer departmentId; @oneToOne @JoinColumn(name = "id") private DepartmentHead departmenthead;}
DepartmentHead.java
@Entity@Table(name="departmenthead", catalog = "student")public class DepartmentHead { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @oneToOne(mappedBy = "departmenthead") private Department department; }
你点
Department在外地
DepartmentHead的
DepartmentHead内场
Department。Hibernate会选择要使用的ID,而无需在实际链接中指定该ID。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)