我在用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不知道什么原因,请知道的帮忙看一下,谢谢!
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不知道什么原因,请知道的帮忙看一下,谢谢!
解决方案 »
- Java servlet 显示多张图片的问题
- Hibernate更新问题
- 急求servlet,jsp,javabean的使用
- 求前端分页组建
- 添加struts2时url patten的三项*.action *.do /*有什么区别
- (讨论)关于pojo、dao、service的困惑
- 在java1.4中如何用schema验证xml的有效性?
- 哪位仁兄可以告诉我怎么下载Spring 源代码吗?谢谢
- EJBQL能否实现模糊查询功能 急,在线等
- 请教大虾 EJB 编译问题
- HttpSessionListener 调用 spring 中服务类的实现方法出现session错误。
- webshpere6.1跟myeclipse6.5整合错误
还是仔细看看你的update语句吧。适当的减少update的次数,直到找到哪个update引起了这个异常
=================================================================异常:
在插入时:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1解决方法:
如果是自增主键?
有的数据库是可以修改自增主键例如:mysql,有的数据库是不允许修改自增主键的例如postgresql
不要设置自增主键的值
其实还有别的方法,你自增主键的话再加个flag字段
0=存在,1=不存在
读取数据的时候+个条件
然后delete的时候就别物理删除了
这样就不会出现你上面的情况了
当然,这样的话,你是能执行成功不报错,但结果你却要去数据库看了
version是乐观锁!
解决办法参考楼上几位!
你加上试试