HHH-13627 Invalidate cache on update for CacheMode GET and IGNORE

This commit is contained in:
Marco Belladelli 2023-03-10 10:20:46 +01:00 committed by Christian Beikov
parent af074e2b1d
commit 3f029e1dde
1 changed files with 9 additions and 1 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.action.internal;
import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.EntityDataAccess;
@ -195,7 +196,7 @@ public class EntityUpdateAction extends EntityAction {
final EntityPersister persister = getPersister();
if ( persister.canWriteToCache() ) {
final SharedSessionContractImplementor session = getSession();
if ( persister.isCacheInvalidationRequired() || entry.getStatus() != Status.MANAGED ) {
if ( isCacheInvalidationRequired( persister, session ) || entry.getStatus() != Status.MANAGED ) {
persister.getCacheAccessStrategy().remove( session, ck );
}
else if ( session.getCacheMode().isPutEnabled() ) {
@ -215,6 +216,13 @@ public class EntityUpdateAction extends EntityAction {
}
}
private static boolean isCacheInvalidationRequired(
EntityPersister persister,
SharedSessionContractImplementor session) {
// the cache has to be invalidated when CacheMode is equal to GET or IGNORE
return persister.isCacheInvalidationRequired() || session.getCacheMode() == CacheMode.GET || session.getCacheMode() == CacheMode.IGNORE;
}
private void handleGeneratedProperties(EntityEntry entry) {
final EntityPersister persister = getPersister();
final Object instance = getInstance();