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

前端 未结 30 3825
夕颜
夕颜 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:37

    In our case we finally found out the root cause of StaleStateException.

    In fact we were deleting the row twice in a single hibernate session. Earlier we were using ojdbc6 lib, and this was ok in this version.

    But when we upgraded to odjc7 or ojdbc8, deleting records twice was throwing exception. There was bug in our code where we were deleting twice, but that was not evident in ojdbc6.

    We were able to reproduce with this piece of code:

    Detail detail = getDetail(Long.valueOf(1396451));
    session.delete(detail);
    session.flush();
    session.delete(detail);
    session.flush();
    

    On first flush hibernate goes and makes changes in database. During 2nd flush hibernate compares session's object with actual table's record, but could not find one, hence the exception.

提交回复
热议问题