我正在使用App Engine的JDO实现的本地开发版本.当我查询包含其他对象作为嵌入字段的对象时,嵌入字段将返回null.
例如,假设这是我坚持的主要对象:
@PersistenceCapable
public class Branch {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String name;
@Persistent
private Address address;
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的嵌入对象:
@PersistenceCapable(embeddedOnly="true")
public class Address {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String street;
@Persistent
private String city;
...
}
Run Code Online (Sandbox Code Playgroud)
以下代码不检索嵌入对象:
PersistenceManager pm = MyPersistenceManagerFactory.get().getPersistenceManager();
Branch branch = null;
try {
branch = pm.getObjectById(Branch.class, branchId);
}
catch (JDOObjectNotFoundException onfe) {
// not found
}
catch (Exception e) {
// failed
}
finally …Run Code Online (Sandbox Code Playgroud)