#1816 Fix for OneToMany relation to non-cached target bean.

This commit is contained in:
rob bygrave
2019-09-12 14:55:37 +12:00
parent 3495d03706
commit d2ece76ca8
5 changed files with 13 additions and 5 deletions
@@ -169,7 +169,7 @@ public class LoadManyRequest extends LoadRequest {
Object parentId = desc.getId(ownerBean);
logger.debug("BeanCollection after lazy load was empty. type:" + ownerBean.getClass().getName() + " id:" + parentId + " owner:" + ownerBean);
}
} else if (isLoadCache()) {
} else if (isLoadCache() && many.isUseCache()) {
Object parentId = desc.getId(bc.getOwnerBean());
desc.cacheManyPropPut(many, bc, parentId);
}
@@ -177,7 +177,7 @@ public class CacheChangeSet {
final ManyKey key;
final List<Object> removes = new ArrayList<>();
final Set<Object> removes = new HashSet<>();
final Map<Object, CachedManyIds> puts = new LinkedHashMap<>();
@@ -82,7 +82,7 @@ class DefaultBeanLoader {
parentDesc.contextPut(pc, parentId, parentBean);
}
boolean useManyIdCache = beanCollection != null && parentDesc.isManyPropCaching();
boolean useManyIdCache = beanCollection != null && parentDesc.isManyPropCaching() && many.isUseCache();
if (useManyIdCache) {
Boolean readOnly = null;
if (ebi.isReadOnly()) {
@@ -226,6 +226,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
desc.registerTable(targetDescriptor.getBaseTable(), this);
}
}
/**
* Return the underlying collection of beans.
*/
@@ -345,7 +346,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
/**
* Add the loaded current bean to its associated parent.
*
* <p>
* Helper method used by Elastic integration when loading with a persistence context.
*/
@Override
@@ -967,6 +968,13 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
elementDescriptor.jsonWriteElement(ctx, element);
}
/**
* Only cache Many Ids if the target bean is also cached.
*/
public boolean isUseCache() {
return targetDescriptor.isBeanCaching();
}
/**
* A Many (element collection) property in bean cache to held as JSON.
*/
@@ -209,7 +209,7 @@ class DLoadManyContext extends DLoadBaseContext implements LoadManyContext {
public void loadMany(BeanCollection<?> bc, boolean onlyIds) {
synchronized (this) {
boolean useCache = context.hitCache && !onlyIds;
boolean useCache = !onlyIds && context.hitCache && context.property.isUseCache();
if (useCache) {
EntityBean ownerBean = bc.getOwnerBean();
BeanDescriptor<?> parentDesc = context.desc.getBeanDescriptor(ownerBean.getClass());