jmix icon indicating copy to clipboard operation
jmix copied to clipboard

Entity cache is not invalidated after entity soft-deleted

Open dtaimanov opened this issue 2 months ago • 1 comments

Environment

Jmix version: 2.7.1

Bug Description

dataManager.remove(..); does not trigger entity cache invalidation. Loading by id (dataManager.load(..).id(..).one()) returns soft deleted entity when cache enabled and throws NoResultException for the same situation when chache is disabled for entity

Steps To Reproduce

  1. Open project jmixCaheTest27.zip
  2. Run test com.company.jmixcahetest27.Ent1Test#test_saveAndLoad with and without line eclipselink.cache.shared.Ent1=true in application.properties E.R.: Results are the same (NoResultException) A.R.: Entity is loaded if cahce is enabled.

Proposed solution

Invalidate entity cache in io.jmix.eclipselink.impl.JmixEntityManager#remove (entityManager.getEntityManagerFactory().getCache().evict(..))

WA

Clear entity cache manually after soft delete:

@Component
public class EntityCacheClearingEventListener {

    @PersistenceContext
    EntityManager em;

    @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
    public void onChangedBeforeCommit(final EntityChangedEvent<?> event) {
        if (event.getType() == EntityChangedEvent.Type.DELETED) {
            em.getEntityManagerFactory().getCache().evict(event.getEntityId().getEntityClass(), event.getEntityId().getValue());
        }
    }
}

dtaimanov avatar Nov 18 '25 12:11 dtaimanov

Source: forum topic.

dtaimanov avatar Nov 18 '25 12:11 dtaimanov