【问题标题】:What is the solution for BatchedTooManyRowsAffectedException?BatchedTooManyRowsAffectedException 的解决方案是什么?
【发布时间】:2019-03-09 11:45:42
【问题描述】:

目前,我们在从特定表中删除记录时遇到以下异常。 我浏览了许多博客和论坛,我才知道它正在发生,因为我们来自 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 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

【问题讨论】:

    标签: java oracle hibernate jdbc


    【解决方案1】:

    我访问了这个链接,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 
    

    【讨论】:

      猜你喜欢
      • 2018-04-02
      • 2013-07-03
      • 1970-01-01
      • 2013-08-02
      • 2019-08-30
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多