Skip to content

Commit 0247c03

Browse files
mbelladebeikov
authored andcommitted
HHH-13627 Invalidate cache on update for CacheMode GET and IGNORE
1 parent 64e9637 commit 0247c03

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.Serializable;
1010

1111
import org.hibernate.AssertionFailure;
12+
import org.hibernate.CacheMode;
1213
import org.hibernate.HibernateException;
1314
import org.hibernate.cache.CacheException;
1415
import org.hibernate.cache.spi.access.EntityDataAccess;
@@ -254,7 +255,7 @@ public void execute() throws HibernateException {
254255

255256
final StatisticsImplementor statistics = factory.getStatistics();
256257
if ( persister.canWriteToCache() ) {
257-
if ( persister.isCacheInvalidationRequired() || entry.getStatus() != Status.MANAGED ) {
258+
if ( isCacheInvalidationRequired( persister, session ) || entry.getStatus() != Status.MANAGED ) {
258259
persister.getCacheAccessStrategy().remove( session, ck );
259260
}
260261
else if ( session.getCacheMode().isPutEnabled() ) {
@@ -288,6 +289,13 @@ else if ( session.getCacheMode().isPutEnabled() ) {
288289

289290
}
290291

292+
private static boolean isCacheInvalidationRequired(
293+
EntityPersister persister,
294+
SharedSessionContractImplementor session) {
295+
// the cache has to be invalidated when CacheMode is equal to GET or IGNORE
296+
return persister.isCacheInvalidationRequired() || session.getCacheMode() == CacheMode.GET || session.getCacheMode() == CacheMode.IGNORE;
297+
}
298+
291299
protected boolean cacheUpdate(EntityPersister persister, Object previousVersion, Object ck) {
292300
final SharedSessionContractImplementor session = getSession();
293301
try {

0 commit comments

Comments
 (0)