org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
原因:
使用hibernate框架的saveOrUpdate(T)方法时,存在T对象的id,如果该实体存在id,该方法就会执行更新操作,从而导致保存时报错。
解决方案一:
去掉实体id对应的@GeneratedValue注解。
解决方案二:
将saveOrUpdate()方法改为save()方法。
注:本人根据自身项目报错而使用的方法,因项目而异。