问题描述
- 麻烦大家帮我看看问题出在哪里
- public class UpdateAction extends DispatchAction {
private UserServiceInter userService;public void setUserService(UserServiceInter userService) { this.userService = userService;}
//修改信息,真正添加到数据库 updateInfo
public ActionForward updateInfo(ActionMapping mapping ActionForm form
HttpServletRequest request HttpServletResponse response) {//将字符串转化为日期类型 DateFormat format = new SimpleDateFormat(""yyyy-MM-dd""); //得到当前用户[从session取出] Users loginUser = (Users) request.getSession().getAttribute(""loginuser""); //从表单中获取修改个人的信息(birthtelwebsitemsnbookmoviemusicsportcartoon) UserForm userForm = (UserForm)form; try{ loginUser.setBirth(format.parse(userForm.getBirth())); }catch(ParseException e){ e.printStackTrace(); } //System.out.println(userForm.getBirth()); //System.out.println(loginUser.getBirth()); loginUser.setTel(userForm.getTel()); loginUser.setWebsite(userForm.getWebsite()); loginUser.setMsn(userForm.getMsn()); loginUser.setBook(userForm.getBook()); loginUser.setMovie(userForm.getMovie()); loginUser.setMusic(userForm.getMusic()); loginUser.setSport(userForm.getSport()); loginUser.setCartoon(userForm.getCartoon()); //保存用户 userService.save(loginUser); return mapping.findForward(""goHomePageUI"");}
}
异常信息如下:
javax.servlet.ServletException: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update指示是userService.save(loginUser);这行代码有问题。求指教
解决方案
其中有一个字段不允许为空,需要给它赋值就可以了
2.DataIntegrityViolationException
not-null
你把数据库中的属性全都改为允许为空!解决问题!
非空属性引用了一个空的或者瞬时(游离状态)的值,可能是引用的值还没有进行持久化吧,还处于游离状态
解决方案二:
看看这张表的hibernate配置,主键是否正确,是否可能会重复
时间: 2024-10-29 07:24:30