0

Currently we are getting following exception during deletion of records from a particular table. I went through many blogs and forums and I came to know that its happening because from DB we are deleting 2 duplicate records but hibernate is expecting 1 record to be deleted. Please correct me if I am wrong.

We thought this issue will be reolved with Oracle 12c Release 2. But even after upgrading Oracle we are still facing this issue.

If you can provide a solution for this isuee it will be very helpful.

Exception :

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 version : Oracle 12c Release 2

Driver version : 11.2

OJDBC Jar : ojdbc6-11.2.0.3

Hibernate Version : 4.1.7

Reference : 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

Rahman
  • 3,755
  • 3
  • 26
  • 43

1 Answers1

0

I visited this link, https://hibernate.atlassian.net/browse/HHH-9134 where someone solved the same problem on save.

    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