BatchedTooManyRowsAffectedException的解决方案是什么?

时间:2018-10-04 06:51:44

标签: java oracle hibernate jdbc

当前,在从特定表中删除记录的过程中,我们遇到以下异常。 我浏览了许多博客和论坛,我知道它的发生是因为从DB 删除2条重复的记录,但休眠状态希望删除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 DB版本: Oracle 12c第2版

驱动程序版本: 11.2

OJDBC Jar: ojdbc6-11.2.0.3

休眠版本: 4.1.7

参考: Oracle JDBC batchUpdate rows affected is always -2 (Statement.SUCCESS_NO_INFO)

Hibernate - Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1

1 个答案:

答案 0 :(得分:0)

我访问了此链接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