【发布时间】:2012-10-15 12:59:01
【问题描述】:
我正在尝试更新 ProfileEntity 中的所有 4000 个对象,但出现以下异常:
javax.persistence.QueryTimeoutException: The datastore operation timed out, or the data was temporarily unavailable.
这是我的代码:
public synchronized static void setX4all()
{
em = EMF.get().createEntityManager();
Query query = em.createQuery("SELECT p FROM ProfileEntity p");
List<ProfileEntity> usersList = query.getResultList();
int a,b,x;
for (ProfileEntity profileEntity : usersList)
{
a = profileEntity.getA();
b = profileEntity.getB();
x = func(a,b);
profileEntity.setX(x);
em.getTransaction().begin();
em.persist(profileEntity);
em.getTransaction().commit();
}
em.close();
}
我猜我从ProfileEntity 查询所有记录的时间太长了。
我该怎么做?
- 我使用的是 Google App Engine,因此无法进行 UPDATE 查询。
编辑于 18 月 10 日
在这 2 天里,我尝试了:
按照 Thanos Makris 的建议使用后端,但走到了死胡同。你可以看到我的问题here。
阅读 DataNucleus 关于 Map-Reduce 的建议,但真的迷路了。
我正在寻找不同的方向。由于我只打算更新一次,也许我可以每 200 个左右的对象手动更新一次。
是否可以查询前 200 个对象,然后查询后 200 个对象,依此类推?
【问题讨论】:
-
你能发布完整的堆栈跟踪吗?
-
那么,我建议使用Task Queue API 来解决这个问题。在那里,通过使用游标,您将能够查询一批实体,更新它们并将它们存储回来。
标签: java google-app-engine jpa