0
votes

I have a java back-end web application that just started throwing an error after some sort of database update.

I've been able to isolate the code to a single line in which a Session variable is being flushed:

Session session=getSession();

session.saveOrUpdate(parm);

session.flush();  //This is where it errors

And it throws this error:

ERROR AbstractFlushingEventListener Could not synchronize database state with session

org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 1 actual row count: 0 expected: 1

The code hasn't changed in over a year; it just started throwing this error.

Any suggestions?

Thanks

1
Please also include the sql statement and the full stack trace during the execution.samabcde
@Tim, is there a change on database side on this table , possible that an autogenerated column is being updated bu this saveOrUpdateTechFree

1 Answers

0
votes

This error usually caused when the hibernate can't find all the rows it needs to update. Meaning that when you try to update some objects that were pulled from the DB they don't really exist anymore (or never existed in the first place).

It might be because another thread is deleting them or that the DB's isolation mode is set to read_uncommited and so rows that were created by another transaction failed to save (due to a transaction failure) and don't exist anymore.

ref: https://stackguides.com/questions/21625059/org-hibernate-stalestateexception-batch-update-returned-unexpected-row-count-fr