【发布时间】:2014-02-12 14:34:19
【问题描述】:
这是我的简单实体:
import com.google.appengine.api.datastore.Key;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable
public class Food {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String name;
@Persistent
private String description;
public Key getId() {
return (id);
}
public void setId(Key id) {
this.id = id;
}
public String getName() {
return (name);
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return (description);
}
public void setDescription(String description) {
this.description = description;
}
}
我正在以这种方式加载我的食物列表:
try {
pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(Food.class);
foods = (List<Food>) q.execute();
} catch (Exception exc) {
exc.printStackTrace();
}
finally {
pm.close();
}
为每个 Food 实体自动生成密钥。我也在使用 HRD。所以...上面的查询 (pm.newQuery(Food.class);) 不具有强一致性,一次返回所有结果,第二次不返回新创建的食物。如何以这种方式更改此查询,每次我从数据库中获取所有食物。在我读过的数据存储文档中应该是祖先查询,但我没有祖先路径。 (我应该说我是数据存储区的新手,仍然从昨天开始学习,但这一次花了我很多时间)。请帮我。
【问题讨论】:
-
不使用父级就无法实现强一致性。这就是重点。要么您使用祖先,要么您接受有时您的查询结果会过时(并使用例如 memcache 来解决这个问题)。
标签: google-app-engine google-cloud-datastore jdo