Myeclipse报错:错误Batch update returned unexpected row count from update [0];


Struts Problem Report

Struts has detected an unhandled exception:
Messages: 	

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

File: 	org/hibernate/jdbc/Expectations.java
Line number: 	85
Stacktraces
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

    org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:686)
    org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
    org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:392)

   对于错误Batch update returned unexpected row count from update [0];对应的中文意思就是:批量更新从更新[0]返回未预期的行计数;简而言之的意思就是,找不到可以更新的那一行,就是找不到相应的id值。

    我在写javaweb中的saveOrUpdate的时候就遇到了这个问题,通过不断的调式,才明白了哪有问题。修改更新带id参数传进去是没问题的。但是你新增的时候,会连带隐藏的id(这时候id=“”而不是null)传进去,而后台hibernate看到id不等于null,便以为是更新,但找不到对应的id进行数据更新,而且系统也没有做相应的报错功能,所以直接变成以上错误。下来来讲解两个我实现过的解决方法。

    在更新表格数据的时候,双击列表,我们需要传参id,新增保存的时候,我们不需要传参id,(ps:id是自增的uuid)。然而为了偷懒,更新修改和新建保存都用的是同一个表格的时候,这才会出问题。

    第一种方法:重复写表格,第一个更新修改的表格,form里带隐含参数,

    第二个表格就把<input type="hidden" ......>删掉即可,对应的URL跳转改好就可以了。


    第二种方法:修改action类,在调用业务层的时候做数据判断,对id的值进行一定的修改,若是id="",即把他改为id=null。








  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值