在 Java 中创建拥有的一对多关系时,我注意到使用低级 Datastore API 和 DataNucleus JDO 之间的结果记录存在差异。不确定这是故意的还是任何解决方法。
例如,
如果以下链接中有员工的多个地址:
https://developers.google.com/appengine/docs/java/datastore/entities#Ancestor_Paths
使用如下低级数据存储 api,员工记录不显示地址列(即属性):
Entity employee = new Entity("Employee");
datastore.put(employee);
Entity address_home = new Entity("Address", employee.getKey());
datastore.put(address_home);
Entity address_mailing = new Entity("Address", employee.getKey());
datastore.put(address_mailing);
使用 JDO,员工记录显示一个地址列(即属性):
@PersistenceCapable
public class Employee {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(mappedBy = "employee")
private List<Address> addresses;
List<Address> getAddresses() {
return addresses;
}
void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}
// ...
}
@PersistenceCapable
public class Address {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private Employee employee;
@Persistent
private String Street;
...
}
额外的财产是无害的。但是,为什么这对 JDO 来说是必需的?
我在开发服务器上使用带有 DataNucleus v2 的 GAE/J 1.7.2。