java - Objectify 不返回新数据

标签 java google-cloud-datastore objectify

我正在使用 Ojectify 来存储数据存储区,我有一个实体,当我保存更改时保留它,但在浏览器中显示它有时会显示以前的数据,有时会显示新数据。

@Entity 
public class BrandDto {
    @Id
    private Long id;
    @Index
    private String name;

    @Index
    private List<Ref<UserDto>> users;

    @Index
    private Integer numeroFollowers;

    getters and setters ..... 
}

它发生在 usersnumeroFollowers 字段中。

我按如下方式更新此数据:

UserDto user = ofy().load().type(UserDto.class).id(p_userId).now();
if (user != null) {
    BrandDto brand = ofy().load().type(BrandDto.class).id(p_brandId).now(); //get(p_brandId);
    List<UserDto> users = brand.getUsers() != null ? brand.getUsers() : new ArrayList<UserDto>();
    if (!users.contains(user)) {
       users.add(user);
    }
    brand.setUsers(users);
    brand.setNumeroFollowers(users.size());
    ofy().save().entity(brand).now();
    return true;
} else {
    return false;
}

我读到的内容如下:

List<BrandDto> brands = ofy().load().type(BrandDto.class).list();

我使用的其他查询:

UserDto user = ofy().load().type(UserDto.class).id(p_userId).now();
Ref<UserDto> ref = Ref.create(user);
List<BrandDto> brands = ofy().load().type(BrandDto.class).filter("users", ref).list();

最佳答案

虽然按键获取操作(例如 load().type(...).id(...))默认情况下是高度一致的,但查询最终是一致的。

以下是更多信息:https://cloud.google.com/developers/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/

关于java - Objectify 不返回新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126867/

相关文章:

java - 在 Google App 引擎中更新实体时出错 - com.google.api.server.spi.SystemService invokeServiceMethod : null java. lang.NullPointerException

java - 使用集合查询

java - GAE无法访问客户端中实体类的公共(public)方法

java - 错误 :Exception [EclipseLink-4002] (Eclipse Persistence Services - 2. 4.1.v20121003-ad44345) : org. eclipse.persistence.exceptions.DatabaseException

java - JPA @OneToOne 在映射到具有子类的抽象@Entity 时抛出错误

python - 更新谷歌云数据存储python中实体的一个属性

java - GAE - Java - 数据存储实体的关键字分类

java - Google App Engine 模块可以像 Maven 模块一样共享源代码吗?

java - maven资源过滤: insert a complete file into a property

java - 如何按正常顺序打印然后反转?