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

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

相关文章:

  • 2021-11-17
  • 2021-05-30
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2021-08-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2021-11-12
  • 2021-09-02
相关资源
相似解决方案