示例: s 我有一个与对象 b、c 和 d 相关的 A 类对象 a。
如果我做:
SelectQuery query = new SelectQuery(A.class);
query.addPrefetch("b").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
query.addPrefetch("c").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
List<?> res = context.performQuery(query);
然后稍后:
SelectQuery query = new SelectQuery(A.class);
query.addPrefetch("d").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
List<?> res = context.performQuery(query);
从 a 到 b 和 c 的关系无效(参见 DataRowUtils 第 115 行)。
我使用的是 Cayenne 3.0.2,但在 3.1 和 3.2M1 版本中的行为似乎相同
有没有办法解决这个问题?
我的想法是用这个函数覆盖 A 类中的 CayenneDataObject:
public void writePropertyDirectly(String propName, Object val) {
if(propName.equals("b") || propName.equals("c")) {
if(val instanceof Fault && readPropertyDirectly(propName) != null) {
return;
}
}
super.writePropertyDirectly(propName, val);
}
这是个坏主意吗?它似乎工作。
加载后,我根本不想从数据库中刷新 b 和 c 。
谢谢