日期:2014-05-18  浏览次数:20699 次

hibernate双向一对一映射添加主键生成策略后出错
有student和family两个实体,为一对一关系
@Entity
@Table(name="student")
public class Student {
@Id 
@Column(length=8)
private String stu_id;//学号 主键 
@Column(length=10,nullable=true)
private String name;//姓名
@Column(length=2,nullable=true)
private String sex;//性别
@Column(length=15,nullable=true)
private String nation;//民族
@Column(length=50,nullable=true)
private String place_stu;//生源地
@Column(length=50,nullable=true)
private String place_bir;//出生地
@Column(length=50,nullable=true)
private String place_nat;//籍贯
@Column(length=50,nullable=true)
private String place_reg;//现户口地
@Column(length=50,nullable=true)
private String place_liv;//现居住地
@Column(length=18,nullable=true)
private String id_card;//身份证
@Temporal(TemporalType.DATE) 
@Column(nullable=true)
private Date birthday;//出生日期
@Column(nullable=true)
private boolean poverty;//贫困
@Column(length=2,nullable=true)
private String politics;//政治面貌(群众,团员,党员)
@Column(length=10,nullable=true)
private String religion;//宗教信仰
@Column(length=50,nullable=true)
private String graduate;//毕业学校
@Column(length=15,nullable=true)
private String tel;//手机
@Column(length=20,nullable=true)
private String email;//e-mail
@Column(length=11,nullable=true)
private String qq;//QQ
@Column(length=20,nullable=true)
private String renren;//人人
@Column(length=20,nullable=true)
private String weibo;//微博
@Column(length=20,nullable=true)
private String weixin;//微信
@Column(length=50,nullable=true)
private String other_contacts;//其他联系方式
@Column(length=2,nullable=true)
private String school_census;//学籍
@Column(nullable=true)
private int edu_start_date;//入学年份
@Column(nullable=true)
private int grade;//年级
@Column(length=10,nullable=true)
private String attention_type;//关注类别
@Column(nullable=true)
private float height;//身高
@Column(nullable=true)
private float weight;//体重
@Column(length=4,nullable=true)
private String blood_type;//血型
@OneToOne
@Fetch(FetchMode.JOIN)
@Cascade(CascadeType.SAVE_UPDATE)
private Family family = new Family();

        /*省略get和set*/
}
@Entity
@Table(name="family")
public class Family {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)  
private long fam_id;//ID 主键
@Column(length=50,nullable=true)
private String address;//通信地址
@Column(length=15,nullable=true)
private String fam_tel;//家庭电话
@Column(length=15,nullable=true)
private String station;//离家最近车站
@Column(length=10,nullable=true)
private String postcode;//邮编
@Column(length=10,nullable=true)
private String mem_one_relation;//家庭成员1关系
@Column(length=10,nullable=true)
private String mem_one_name;//家庭成员1姓名
@Column(length=50,nullable=true)
private String mem_one_workunit;//家庭成员1工作单位
@Column(length=15,nullable=true)
private String mem_one_tel;//家庭成员1联系方式
@Column(length=50,nullable=true)
private String mem_one_position;//家