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

前端 未结 30 3839
夕颜
夕颜 2020-11-28 20:47

I get following hibernate error. I am able to identify the function which causes the issue. Unfortunately there are several DB calls in the function. I am unable to find the

30条回答
  •  执念已碎
    2020-11-28 21:28

    I was facing same issue. The code was working in the testing environment. But it was not working in staging environment.

    org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 3; expected: 1
    

    The problem was the table had single entry for each primary key in testing DB table. But in staging DB there was multiple entry for same primary key. ( Problem is in staging DB the table didn't had any primary key constraints also there was multiple entry.)

    So every time on update operation it gets failed. It tries to update single record and expect to get update count as 1. But since there was 3 records in the table for the same primary key, The result update count finds 3. Since expected update count and actual result update count didn't match, It throws exception and rolls back.

    After the I removed all the records which have duplicate primary key and added primary key constraints. It is working fine.

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

    actual row count: 0 // means no record found to update
    update: 0 // means no record found so nothing update
    expected: 1 // means expected at least 1 record with key in db table.

    Here the problem is that the query trying to update a record for some key, But hibernate didn't find any record with the key.

提交回复
热议问题