2010-03-21 91 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