Hibernate——org.hibernate.StaleStateException: Batch update returned unexpected row count from update

来源:互联网 发布:英语语言变迁 知乎 编辑:程序博客网 时间:2024/04/20 10:38

update 2.0:

我的id的类型用的是int,结果无论怎样都报错。后来将类型换为Integer,然后在更新数据之前,使用了setId方法设置了以下记录的ID,再更新就OK了。

总结:
主键最好使用Integer这样的包装类型,而不是int这样的基本类型!,这样可能会避免很多问题。


以下为1.0原文:

在使用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方法设置主键值。

0 0
原创粉丝点击