我使用datanucleus和MongoDB来存储我的对象。我发现了延迟加载的问题。
我班上的一个是:
public class Member implements Serializable{
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent(defaultFetchGroup = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private String key;
private String username;
@Persistent(defaultFetchGroup="true",dependent="true")
private Parameter param = null;
}
检索此对象的代码是:
Transaction tx = pm.currentTransaction();
tx.begin();
Member member = pm.getObjectById(Member.class,"MyID");
tx.commit();
//if I check here, the field "param" is null.
当我检查时,字段“param”为空。但是,我将元数据设置为默认加载param。也许驱动程序MongoDB-JDO不支持元数据“defaultFetchGroup”。
你能告诉我会发生什么吗?
非常感谢。
答案 0 :(得分:1)
情况“在这里”(在交易之外)完全取决于object lifecycle以及您启用的持久性选项。该链接定义了它。可能对象是HOLLOW,因此字段已被卸载并且您没有设置“datanucleus.RetainValues”