我在用hibenate实现数据库操作时有一个表用的是联合主键,表里有一个version字段,但是不是hibernate本身锁的version,并没有加锁,但是当我在对这个表的数据实现更新操作时报下面的错误:
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
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1不知道什么原因,请知道的帮忙看一下,谢谢!

解决方案 »

  1.   

    unexpected row count from update [0]; actual row count: 0; expected: 1 这个是因为你更新某个数据,比如where id=3可是你的数据库里已经没有id=3的数据了,导致了这个异常。
    还是仔细看看你的update语句吧。适当的减少update的次数,直到找到哪个update引起了这个异常
      

  2.   

    org.hibernate.StaleStateException: Unexpected row count: 0 expected: 11).使用的是hibernate的saveOrUpdate方法保存实例。saveOrUpdate方法要求ID为null时才执行SAVE,在其它情况下执行UPDATE。在保存实例的时候是新增,但你的ID不为null,所以使用的是UPDATE,但是数据库里没有主键相关的值,所以出现异常。
    =================================================================异常:
    在插入时:
    org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1解决方法:
    如果是自增主键?
    有的数据库是可以修改自增主键例如:mysql,有的数据库是不允许修改自增主键的例如postgresql
    不要设置自增主键的值
      

  3.   

    晚了
    其实还有别的方法,你自增主键的话再加个flag字段
    0=存在,1=不存在
    读取数据的时候+个条件
    然后delete的时候就别物理删除了
    这样就不会出现你上面的情况了
    当然,这样的话,你是能执行成功不报错,但结果你却要去数据库看了
      

  4.   

    来晚了!
    version是乐观锁!
    解决办法参考楼上几位!
      

  5.   

    你的页面在修改的时候没有把version 传过去吧
    你加上试试
      

  6.   

    免费教你提高工资的网站http://shyboy10228.blog.163.com/