From 21bd9a6a9f2357376fb44c7de63760b18738652b Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 22 May 2018 17:45:03 -0400 Subject: [PATCH] HHH-12587 - Fix NullPointerException when flushing entity with CacheConcurrencyStrategy.NONE. --- .../persister/entity/AbstractEntityPersister.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 4c5db14fcb..9f2b94c78c 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -534,7 +534,7 @@ public abstract class AbstractEntityPersister this.navigableRole = new NavigableRole( persistentClass.getEntityName() ); if ( creationContext.getSessionFactory().getSessionFactoryOptions().isSecondLevelCacheEnabled() ) { - this.canWriteToCache = persistentClass.isCached(); + this.canWriteToCache = determineCanWriteToCache( persistentClass, cacheAccessStrategy ); this.canReadFromCache = determineCanReadFromCache( persistentClass ); this.cacheAccessStrategy = cacheAccessStrategy; this.isLazyPropertiesCacheable = persistentClass.getRootClass().isLazyPropertiesCacheable(); @@ -907,6 +907,14 @@ public abstract class AbstractEntityPersister return false; } + private boolean determineCanWriteToCache(PersistentClass persistentClass, EntityDataAccess cacheAccessStrategy) { + if ( cacheAccessStrategy == null ) { + return false; + } + + return persistentClass.isCached(); + } + @SuppressWarnings("unchecked") private boolean determineCanReadFromCache(PersistentClass persistentClass) { if ( persistentClass.isCached() ) {