#2144 - Fix for NPE via Wrong beans in PersistContext avoid proper lazy load

This commit is contained in:
rob bygrave
2021-01-19 22:37:15 +13:00
parent a4b8be61e3
commit ade36582a0
4 changed files with 12 additions and 8 deletions
@@ -215,7 +215,6 @@ class DefaultBeanLoader {
desc.contextPut(pc, id, bean);
ebi.setPersistenceContext(pc);
}
// desc.contextPut(pc, id, bean); // this will fix one of the two tests
boolean draft = desc.isDraftInstance(bean);
if (embeddedOwnerIndex == -1) {
@@ -245,7 +244,6 @@ class DefaultBeanLoader {
// and put the data into the original bean
query.setUsageProfiling(false);
query.setPersistenceContext(pc);
query.setMode(mode);
query.setId(id);
@@ -1872,6 +1872,17 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
return query.setId(id).findOne();
}
/**
* Create a reference with a check for the bean in the persistence context.
*/
public EntityBean createReference(Boolean readOnly, Object id, PersistenceContext pc) {
Object refBean = contextGet(pc, id);
if (refBean == null) {
refBean = createReference(readOnly, false, id, pc);
}
return (EntityBean)refBean;
}
/**
* Create a reference bean based on the id.
*/
@@ -313,8 +313,7 @@ final class BeanDescriptorCacheHelp<T> {
List<Object> idList = entry.getIdList();
bc.checkEmptyLazyLoad();
for (Object id : idList) {
Object refBean = targetDescriptor.createReference(readOnly, false, id, persistenceContext);
many.add(bc, (EntityBean) refBean);
many.add(bc, targetDescriptor.createReference(readOnly, id, persistenceContext));
}
return true;
}
@@ -296,10 +296,6 @@ public final class DefaultPersistenceContext implements PersistenceContext {
}
private void put(Object id, Object b) {
Object existing = map.get(id);
if (existing != null && existing != b) {
System.out.println("DEBUG: Overwriting object");
} // else // will fix both tests
map.put(id, b);
}