首页 > 技术文章 > org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

aishangtaxuefeihong 2017-10-18 16:21 原文

 

在使用hibernate更新数据库记录的信息时,出现org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 错误。

原因分析: 
我在更新数据时,显式地使用了id的setId()方法为其指定值。但是我的实体类的id指定了主键生成策略(@GeneratedValue(strategy = GenerationType.AUTO)),此时不能显式使用setId()方法设置id的值。

解决方法: 
不要显式地使用setId方法设置主键值。

推荐阅读