HHH-18098 don't write to cache when entity extends with @Cacheable(false)

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-10 23:38:03 +02:00
parent 47da22183b
commit 7b0d66782d
1 changed files with 8 additions and 4 deletions

View File

@ -869,10 +869,14 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
PersistenceContext persistenceContext,
Object entityIdentifier,
Object version) {
// No need to put into the entity cache if this is coming from the query cache already
final EntityDataAccess cacheAccess = concreteDescriptor.getCacheAccessStrategy();
if ( !rowProcessingState.isQueryCacheHit() && cacheAccess != null && session.getCacheMode().isPutEnabled() ) {
putInCache( toInitialize, session, persistenceContext, entityIdentifier, version, cacheAccess );
if ( concreteDescriptor.canWriteToCache()
// No need to put into the entity cache if this is coming from the query cache already
&& !rowProcessingState.isQueryCacheHit()
&& session.getCacheMode().isPutEnabled() ) {
final EntityDataAccess cacheAccess = concreteDescriptor.getCacheAccessStrategy();
if ( cacheAccess != null ) {
putInCache( toInitialize, session, persistenceContext, entityIdentifier, version, cacheAccess );
}
}
}