0
我正在使用Ojectify存儲數據存儲,我有一個實體,當我保留它時,如果保存更改,但在瀏覽器中顯示它有時會顯示我以前的數據,有時會顯示新的數據。Objectify不返回新數據
@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 .....
}
它發生在users
和numeroFollowers
領域。
我作如下更新此數據:
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();