Prevent EntityNotFoundException when ID doesn't exist in the DB (#21867)

This makes the behavior consistent with the other store implementations.

Closes #21866
This commit is contained in:
Alexander Schwartz 2023-07-25 13:43:38 +02:00 committed by GitHub
parent 82f28f3bae
commit 23f3a1a872
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -262,7 +262,11 @@ public abstract class JpaMapStorage<RE extends JpaRootEntity, E extends Abstract
UUID uuid = UUIDKey.INSTANCE.fromStringSafe(key);
if (uuid == null) return false;
removeFromCache(key);
em.remove(em.getReference(entityType, uuid));
// First find the entity, as just trying to remove it will throw an EntityNotFoundException
RE entity = em.find(entityType, uuid);
if (entity != null) {
em.remove(entity);
}
logger.tracef("tx %d: delete entity %s", hashCode(), key);
return true;
}