gpt4 book ai didi

java - Objectify 不返回新数据

转载 作者:行者123 更新时间:2023-12-02 05:14:05 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com