Row was updated or deleted by another transaction

Row was updated or deleted by another transaction

While working with hibernate (which is quite popular java object relational mapper), you might have stumbled upon this exception:

Row was updated or deleted by another transaction

What does this exception really mean? Well, you're most probably trying to update an object via hibernate which was version ID is lower than version ID of object in the database.

Hibernate uses versioning to know that modified object you had is older than one which is currently persisted.

Hope this will help some java newbies which are using hibernate for persistence.

What is the solution to "row was updated or deleted by another transaction" then?

Solution

You need to get the very latest version of object to avoid "row was updated ... " exception before you make any changes.

This can be usually accomplished by adding:

MyEntity myEntity = persistenceManager.findObjectById(myEntity .getId())

here goes then:

persistenceManager.update(myEntity);

on your hibernate persistence manager


Related Posts