Stale state exception not thrown for versioned table when row is deleted

For versioned table, when a thread tries to update the row which is deleted in DB, stale state exception is expected to be thrown, but often it is not worked as expected.

After checking in the code, when merge flow is hit, there is select operation done and when result is null (row is deleted) entityIsTransient is triggered to do an insert operation rather than throwing the exception in case of versioned table.

Code block: org.hibernate.event.internal.DefaultMergeEventListener

if ( result == null ) {
			//TODO: we should throw an exception if we really *know* for sure
			//      that this is a detached instance, rather than just assuming
			//throw new StaleObjectStateException(entityName, id);

			// we got here because we assumed that an instance
			// with an assigned id was detached, when it was
			// really persistent
			entityIsTransient( event, copyCache );
		}

Issue is seen in 5.6.10. But there is no change in source code even in latest 6.1.4.0 version as well.

Note: If row is present during this check and deleted before update, then, StaleStateException is seen as expected.

You are hitting [HHH-1661] - Hibernate JIRA which we currently work on.

Hi @beikov Thanks for the response.
I see the comment on that issue is almost 7 years old and I see fix version in the ticket as 6.2.0. Can you please let us know when we can expect 6.2.0 and if the same changes can be patched to 5.x.x version.

Appreciate your support.

We will most likely backport this to at least 6.1. If the implementation is easy enough, then it will probably be also backported to 5.6.

1 Like