Skip to content

Commit

Permalink
Added a precautionary removal of a cached record when there is an opt…
Browse files Browse the repository at this point in the history
…imistic lock failure.
  • Loading branch information
Eddie Carpenter committed Aug 26, 2024
1 parent 813a273 commit bead3af
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void setConnectionName(String connectionName)
this.connectionName = connectionName;
}

@SuppressWarnings({"java:S1141", "java:S2077", "tainting"})
@SuppressWarnings({"java:S1141", "java:S2077"})
//Having try-resource in a bigger try block is allowed. Dynamically formatted SQL is verified to be safe
@Override
@Nonnull
Expand Down Expand Up @@ -804,6 +804,15 @@ else if (entity._getMetaData().isCacheable() && cacheStoreMode != CacheStoreMode
*/
else if (action != INSERT && isOptimisticLocked(entity)) {
setRollbackOnly();

/*
Delete the cached record for the rare case where a cached record might be out of date.
NOTE: This is highly unlikely and an error in itself.
*/
if (entity._getMetaData().isCacheable()) {
l2Cache().evict(entity._getEntityClass(), entity._getPrimaryKey());
}//if

throw new OptimisticLockException(entity);
}//else if
}//try
Expand Down

0 comments on commit bead3af

Please sign in to comment.