2010-03-21 38 views
1

任何机构都知道如何在JPA中使用Datastore游标?如何在GAE上使用数据存储区游标与jpa

+1

这是你的数据存储光标是什么意思? - http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Cursor.html – Bozho 2010-03-21 09:43:49

+0

但是没有任何使用JPA的游标示例 – Mecid 2010-03-21 13:34:36

回答

2

你可以试试这个(改编自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... 
+0

这似乎不正确。你在这里使用的Query类有一个setRange()方法,因为它是一个javax.jdo.Query。 JPA中使用的Query类是javax.persistence.Query,并且没有setRange()方法。 – Linc 2010-09-15 19:13:53

+0

@Linc你是对的。解决...... – 2010-09-15 19:29:15

相关问题