hibernate中有外键的表插入数据报错:not-null property references a null or transient value
报错信息:
not-null property references a null or transient value: com.....model.User.advilige; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.....model.User.advilige
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.....model.User.advilige
系统是struts spring hibernate架构,功能是注册。
1,在struts的action的execute方法加载user信息:
...
String img = (String)((RegUser)form).getImage();
String adv = (String)((RegUser)form).getAdv();
Advilige ad = new Advilige(adv);
Img im = new Img(img);
u.setUserName(username);
u.setUserPass(password);
u.setUsernick(usernick);
u.setEmail(email);
u.setImg(im);
u.setAdvilige(ad);
if(regdao.RegUser(u)){
return (map.findForward("success"));
}
其中setImg方法和setAdvilige方法是两个外键,此处我直接加载不知道是否有问题。
2,在spring的DAO里申明保存User信息的方法:
public boolean RegUser(User u){
try{
this.getHibernateTemplate().save(u);
}catch...
}
此处我不知道直接这个save是否会有问题,因为还关联两个外键对应着img和advilige表,不知道这里是不是要进行那两个表的load或者别的处理。
问题着急,大家帮忙!