I just started using JDO and Google datastore
I have File class that contains code below for primary key.
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
When I call this method, using ID/Name value in datastore, it gave me error - javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind File with key File("6298002603900928").
But when I use Key value which in datastore, it returns the expected File object
ID/Name value is 6298002603900928
Key value is agxvcmdhbml6ZS1mcHZyEQsSBEZpbGUYgICAgICAmAsM
File file = null;
// get data from Google datastore
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
file = pm.getObjectById(File.class, fileId);
} catch (JDOObjectNotFoundException e) {
e.printStackTrace();
}
How do I solve this problem?
I tried to convert ID/Name to Key by using this code
Key key = KeyFactory.stringToKey(fileId);
But it also gave me error java.lang.IllegalArgumentException: Invalid Key PB: no elements.
I found out why is there error.
fileId that I used is String. It is suppose to be Long.