java - BatchedTooManyRowsAffectedException 的解决方案是什么?
问题描述
目前,我们在从特定表中删除记录时遇到以下异常。我浏览了许多博客和论坛,我才知道它的发生是因为我们从 DB 中删除了 2 条重复记录,但 hibernate 期望删除 1 条记录。如果我错了,请纠正我。
我们认为这个问题将在 Oracle 12c 第 2 版中得到解决。但即使在升级 Oracle 之后,我们仍然面临这个问题。
如果您可以为此问题提供解决方案,那将非常有帮助。
例外 :
org.springframework.orm.hibernate3.HibernateSystemException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1; nested exception is org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:103)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.orm.jpa.JpaAccessor.translateIfNecessary(JpaAccessor.java:155)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:192)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:150)
Oracle 数据库版本: Oracle 12c 第 2 版
驱动程序版本: 11.2
OJDBC 罐: ojdbc6-11.2.0.3
休眠版本: 4.1.7
参考: Oracle JDBC batchUpdate 受影响的行始终为 -2 (Statement.SUCCESS_NO_INFO)
解决方案
我访问了这个链接,https://hibernate.atlassian.net/browse/HHH-9134,有人在保存时解决了同样的问题。
Article article = new Article();
article.setName("test");
List<Section> articles = article.getSections(); //ArrayList
Section section1 = new Section();
section1.setName("test");
section1.setContent("test");
articles.add(section1);
Section section2 = new Section();
section2.setName("test");
section2.setContent("test");
articles.add(section2);
Section section3 = new Section();
section3.setName("test");
section3.setContent("test");
articles.add(section3);
session.save(article); //throw exception here
Article article = articleManager.get(1L);
article.setName("test");
List<Section> articles = new ArrayList<Section>();
Section section1 = new Section();
section1.setName("test");
section1.setContent("test");
articles.add(section1);
Section section2 = new Section();
section2.setName("test");
section2.setContent("test");
articles.add(section2);
Section section3 = new Section();
section3.setName("test");
section3.setContent("test");
articles.add(section3);
article.setSections(sections);
session.save(article); //throw exception here
Article article = articleManager.get(1L);
article.setName("test");
List<Section> articles = article.getSections(); //PersistentList
articles.clear();
Section section1 = new Section();
section1.setName("test");
section1.setContent("test");
articles.add(section1);
Section section2 = new Section();
section2.setName("test");
section2.setContent("test");
articles.add(section2);
Section section3 = new Section();
section3.setName("test");
section3.setContent("test");
articles.add(section3);
session.save(article); // it works fine
推荐阅读
- python - 获取哈希表中满足特定算术属性的所有键
- python - 树莓派 3B+ 成功连接配对,但无法接收来自 OBD II 的数据
- java - 过程或函数“search_words1”需要参数“@result”,但未提供该参数
- android - 在 armeabi-v7a 中,streqh 导致“无效指令,您的意思是:strexh,strh?”。“eq”去哪儿了?
- matlab - NN 模型输出一个类别进行二元分类
- excel - 如何使用 VBA 中的“TimeIf”函数从用户在用户表单中输入的时间中减去特定时间?
- merge - Cherry-pick 提交及其合并提交而不解决冲突
- sql-server - SQL Server - 更新和选择
- c++ - 实例化后可以构造吗?避免空构造函数
- angular - Angular:更改检测破坏了计时器