From 5b9ef2daecaa9ced2c99cea867c611115f8aefdb Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 7 Sep 2023 14:44:17 +1200 Subject: [PATCH] [12x] Backport of fix for #3173 BeanSet init(), initClear() and BeanMap - BeanSet init() and initClear() load with onlyIds false because the expectation is that with BeanSet the equals/hashCode implementation can use a property - BeanMap lazy loading, include the mapKey if defined in the lazy loading query --- ebean-api/src/main/java/io/ebean/common/BeanSet.java | 4 ++-- .../main/java/io/ebeaninternal/api/LoadManyRequest.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ebean-api/src/main/java/io/ebean/common/BeanSet.java b/ebean-api/src/main/java/io/ebean/common/BeanSet.java index 0c6f0c508..18390ab55 100644 --- a/ebean-api/src/main/java/io/ebean/common/BeanSet.java +++ b/ebean-api/src/main/java/io/ebean/common/BeanSet.java @@ -117,7 +117,7 @@ public final class BeanSet extends AbstractBeanCollection implements Set(); } @@ -134,7 +134,7 @@ public final class BeanSet extends AbstractBeanCollection implements Set(); } else { - lazyLoadCollection(true); + lazyLoadCollection(false); } } } finally { diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java b/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java index dcbc3c32b..cb3c932ea 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java @@ -97,8 +97,12 @@ public final class LoadManyRequest extends LoadRequest { // potentially changes the joins, selected properties, cache mode loadContext.configureQuery(query); if (onlyIds) { - // lazy loading invoked via clear() and removeAll() - query.select(many.targetIdProperty()); + String mapKey = many.mapKey(); + if (mapKey != null) { + query.select(mapKey); + } else { + query.select(many.targetIdProperty()); + } } return query; }