Reputation: 193
My datastore table is named document and has is structured in the following matter: Key, Write Ops, ID/Name, html, name. Sample data is:
Key: aglub19hcHBfaWRyDgsSCGRvY3VtZW50GAEM
Write Ops:6
ID/Name:1
html:"<div>something</div>
name: "Untitled name"
Where the first three columns are created by Google App Engine. I fetch the entities from datastore with the code below:
int PAGE_SIZE = 20;
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery queryString = datastore.prepare(new Query("document"));
int rowCount = queryString.countEntities();
int offset = 0;
//fetch results from datastore based on offset and page size
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(PAGE_SIZE);
QueryResultList<Entity> results = queryString.asQueryResultList(fetchOptions .offset(offset));
A problem occurs when I try to retreive the Key column from entity with .getKey() method. Instead of returning the random string from column Key it returns document("1). Is there a way to get Keys from the results array?
Upvotes: 1
Views: 403
Reputation: 600059
The key is not a "random string". It's a string encoding of the Key object.
I use the Python API rather than the Java one, but in Python you can simply call str()
on the Key instance to get the encoded version. In Java you might be able to use key.toString()
, or you may need to serialize it in some way.
Upvotes: 2