不常发疯的疯子 2015-06-13 23:28 采纳率: 0%
浏览 3482

数据库中更新信息时,id要相同(id为主键),可以办到吗?

如题,我现在报这个错误:org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.bysj.songxy.domain.Teachers#2]
我用的是springmvc架构
DAO层:
public void update(T o){
getSession().update(o);
}

service层:
public ResultBase update(Long id,String password) {
ResultBase ret = new ResultBase();
Teachers teachers = new Teachers();
teachers.setId(id);
teachers.setPassword(Md5Util.md5Others(password));
teachersDAO.update(teachers);
ret.setResult(ResultBase.RESULT_SUCC);
return ret;
}

controller层:
public String goTpasswordchange(Long id,String oldpassword,String password, ModelMap map){

Teachers teachers = teachersService.findById(id);
map.addAttribute("id", id);
String Mpasseord=Md5Util.md5Others(oldpassword);
System.out.println(Mpasseord);
System.out.println(teachers.getPassword());
if(teachers.getPassword().equals(Mpasseord)){
teachersService.update(id,password);
System.out.println("修改成功");
return "main/Tindex";
}
else{
System.out.println("修改失败");
return "main/Tpasswordchange";
}
}

有木有大神知道怎么修改?很急,在线等

  • 写回答

8条回答

  • 不常发疯的疯子 2015-06-14 00:12
    关注

    顶一下,有木有大神T T

    评论

报告相同问题?