org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

错误原因:

   使用hibernate的saveOrUpdate方法保存实例。saveOrUpdate方法要求ID为null时才执行SAVE, 在其它情况下执行UPDATE。在保存实例的时候是新增,但你的ID不为null,所以使用的是UPDATE,但是数据库里没有主键相关的值,所以出现异 常。 

 

在Action中JAVA代码:

public String updateStudent(){

Student s = new Student();

try {
BeanUtils.copyProperties(s, student); //利用反射机制对JavaBean的属性进行处理,减少代码量
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

s.setId(id); //将页面中获得要更新学生的id号
studentService.updateStudent(s);

return querystudent();
}

注意:BeanUtils导入的是org.apache.commons.beanutils.BeanUtils。

用法可查看下面链接http://www.cnblogs.com/fayf/archive/2008/08/21/1272982.html

以上仅代表个人观点,欢迎大家拍砖(*^_^*)

posted on 2015-04-02 14:28  福兰文文  阅读(1223)  评论(0编辑  收藏  举报