From 9dd28d88796331dbdcb0abb8515dafcd7e92d122 Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Wed, 20 Jan 2021 21:10:49 +1300 Subject: [PATCH] #2146 - Fix for Cache with lazy load doesnt work When the list is empty() it has already been loaded and loading should skip the l2 cache --- .../server/loadcontext/DLoadBeanContext.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java index 6c796501f..454fd6dac 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java @@ -56,7 +56,6 @@ class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext { } private void configureQuery(SpiQuery query, String lazyLoadProperty) { - if (cache) { query.setBeanCacheMode(CacheMode.ON); } @@ -70,7 +69,6 @@ class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext { } protected void register(EntityBeanIntercept ebi) { - if (currentBuffer.isFull()) { currentBuffer = createBuffer(secondaryBatchSize); } @@ -198,8 +196,10 @@ class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext { // lazy load property was a Many return; } - - if (context.hitCache) { + if (list.isEmpty()) { + // re-add to the batch and lazy load from DB skipping l2 cache + list.add(ebi); + } else if (context.hitCache) { Set hits = context.desc.cacheBeanLoadAll(list, persistenceContext, ebi.getLazyLoadPropertyIndex(), ebi.getLazyLoadProperty()); list.removeAll(hits); if (list.isEmpty() || hits.contains(ebi)) {