【问题标题】:How to use datastore cursors with jpa on GAE如何在 GAE 上将数据存储游标与 jpa 一起使用
【发布时间】:2011-01-30 00:03:38
【问题描述】:

有人知道如何将数据存储游标与 JPA 一起使用吗?

【问题讨论】:

标签: java google-app-engine jpa google-cloud-datastore cursors


【解决方案1】:

你能试试这个吗(改编自JDO sample):

List<Employee> results = (List<Employee>) query.execute();
// Use the first 20 results...

Cursor cursor = JPACursorHelper.getCursor(results);
String cursorString = cursor.toWebSafeString();
// Store the cursorString...

// ...

// Query query = the same query that produced the cursor
// String cursorString = the string from storage
Cursor cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
query.setFirstResult(0);
query.setMaxResults(20);

List<Employee> results = (List<Employee>) query.execute();
// Use the next 20 results...

【讨论】:

  • 这似乎不正确。您在这里使用的 Query 类有一个 setRange() 方法,因为它是一个 javax.jdo.Query。 JPA 中使用的 Query 类是 javax.persistence.Query 并且没有 setRange() 方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多