How to use datastore cursors with jpa on GAE
Asked Answered
S

1

1

Any body know how to use Datastore Cursors with JPA?

Stilliform answered 21/3, 2010 at 9:35 Comment(2)
is this what you mean by datastore cursors? - code.google.com/appengine/docs/java/javadoc/com/google/…Nicodemus
but there is no any sample for using cursors with JPAStilliform
L
2

Can you try this (adapted from the 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...
Loraleeloralie answered 21/3, 2010 at 21:12 Comment(1)
This does not seem correct. The Query class you're using here has a setRange() method because it's a javax.jdo.Query. The Query class that is used in JPA is javax.persistence.Query and does not have a setRange() method.Clapp

© 2022 - 2024 — McMap. All rights reserved.