hibernate更新数据的时候,如果数据不存在,就报org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 这个错误。报错的信息有点像junit的断言。期望的是一行,实际上是0行。
我的更新方法是: this.getHibernateTemplate().update(entity);
解决办法就是:自己写sql语句。
--------------------------------------------------
为什么会这样呢?我敢肯定的是jdbc如果执行更新操作的时候,如果数据库里面没有对应的数据,不会报错。而hibernate的官方文档明确说明了,如果没有数据而执行了更新操作,就报以上的错误。
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actua
原文:http://blog.csdn.net/zl544434558/article/details/20151681