Fix Cache To have immutable entities (#21933)

This commit is contained in:
Mohit Yadav 2025-06-25 05:10:32 +05:30 committed by GitHub
parent 2aa2282e03
commit 16aa38da8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -681,7 +681,9 @@ public abstract class EntityRepository<T extends EntityInterface> {
CACHE_WITH_ID.invalidate(new ImmutablePair<>(entityType, id));
}
@SuppressWarnings("unchecked")
T entity = (T) CACHE_WITH_ID.get(new ImmutablePair<>(entityType, id));
T entity =
JsonUtils.deepCopy(
(T) CACHE_WITH_ID.get(new ImmutablePair<>(entityType, id)), entityClass);
if (include == NON_DELETED && Boolean.TRUE.equals(entity.getDeleted())
|| include == DELETED && !Boolean.TRUE.equals(entity.getDeleted())) {
throw new EntityNotFoundException(entityNotFound(entityType, id));
@ -756,7 +758,9 @@ public abstract class EntityRepository<T extends EntityInterface> {
CACHE_WITH_NAME.invalidate(new ImmutablePair<>(entityType, fqn));
}
@SuppressWarnings("unchecked")
T entity = (T) CACHE_WITH_NAME.get(new ImmutablePair<>(entityType, fqn));
T entity =
JsonUtils.deepCopy(
(T) CACHE_WITH_NAME.get(new ImmutablePair<>(entityType, fqn)), entityClass);
if (include == NON_DELETED && Boolean.TRUE.equals(entity.getDeleted())
|| include == DELETED && !Boolean.TRUE.equals(entity.getDeleted())) {
throw new EntityNotFoundException(entityNotFound(entityType, fqn));