列如:
有两张表:
Student表: 有字段: sid,sname
Classes表: 有字段:cid,sname,studid
怎么配置一对一唯一外键注解呀,求帮助?
在职员类写
这是多对一
@ManyToOne(targetEntity = SysDepartment.class,fetch=FetchType.EAGER)
@JoinColumn(name = "department_id")
private SysDepartment departments; //通过部门编号与部门类建立关系
在部门类写
这是一对多
@OneToMany(targetEntity = com.entity.SysEmployee.class,fetch=FetchType.EAGER)
@JoinColumn(name = "department_id")
private Set employees = new HashSet(); //与职员类建立关系
1对1,http://ryxxlong.iteye.com/blog/622652
其实你这个应该是1对多(1个班级对应多个学生),http://www.cnblogs.com/wangchenyang/archive/2011/08/23/2150323.html
@OneToOne
@JoinColumn(name="student_sid",insertable=true,unique=true)
private Integer stuid;