Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

用Hibernate保存对象的时候,Eclipse后台提示出现这个错误:【Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1】,原因是给id设置了自动生成策略,但是却给这个对象的id手动设置了值,Hibernate在其自身的缓存中根据此id找不到对象,就会报这个错。

解决的方法很简单(以下2选1):

1.去除id主键的自动生成策略。

2.将id赋值为空(只适用于不需要预先建立id的情况)。

"渴望飞翔的人不会甘心于爬行。"

原文地址:https://www.cnblogs.com/yanggb/p/12848387.html