gpt4 book ai didi

java - 事务中的祖先查询(objectify)返回数据 "frozen in time"

转载 作者:行者123 更新时间:2023-11-30 03:42:20 25 4
gpt4 key购买 nike

直接举例:

@Entity
public class Parentt {
@Id
String id;
}

@Entity
public class Child {
@Parent
Ref<Parentt> parenttRef;
@Id
String id;
}

public void test() {
final Parentt parentt = new Parentt();
ofy().transact(new VoidWork() {
@Override
public void vrun() {

parentt.setId(UUID.randomUUID().toString());
ofy().save().entity(parentt).now();
Child child = new Child();
child.setId(UUID.randomUUID().toString());
child.setParentt(parentt.getId());
ofy().save().entity(child).now();

LOG.info("query result size: " + ofy().load().type(Child.class).ancestor(parentt).list().size());
ofy().flush();
LOG.info("query result size: " + ofy().load().type(Child.class).ancestor(parentt).list().size());

}
});

LOG.info("query result size(outside of transaction): " + ofy().load().type(Child.class).ancestor(parentt).list().size());
}

test()方法内的代码生成的结果:

query result size: 0

query result size: 0

query result size(outside of transaction): 1

我在 Objectify 文档中找到了:

There are some quirks at the low-level API: For example, get()s and query()s will see the datastore "frozen in time" and will not reflect updates even within the transaction. Objectify hides this behavior from you; subsequent fetches will see the same data seen (or updated) previously. Note that since queries are always run inside of GAE, indexes (ie, filtering operations) always appear to be frozen in time - Objectify can't hide this.

祖先查询是否基于内部索引,这就是查询在事务内部不返回结果的原因(这里除了父级之外没有其他过滤)?

最佳答案

查询本质上是基于索引的 - 它们通过到 GAE 的往返来提供服务。因此 GAE 的行为定义了返回值。 Objectify 在这里确实无能为力。

关于java - 事务中的祖先查询(objectify)返回数据 "frozen in time",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26567879/

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