In Entity's method getKey()
states:
Returns the Key that represents this Entity. If the entity has not yet been saved (e.g. via DatastoreService.put), this Key will not be fully specified and cannot be used for certain operations (like DatastoreService.get). Once the Entity has been saved, its Key will be updated to be fully specified.
What does the fully specified mean?
In following test, keys are the same before and after DatastoreService#put(Entity)
:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity e = new Entity("Person", "John");
System.out.println(e.getKey()); // Person("John")
System.out.println(KeyFactory.keyToString(e.getKey())); // output: aglub19hcHBfaWRyEAsSBlBlcnNvbiIESm9obgw
Key k = ds.put(e);
System.out.println(k); // output: Person("John")
System.out.println(KeyFactory.keyToString(k)); // output: aglub19hcHBfaWRyEAsSBlBlcnNvbiIESm9obgw
Aucun commentaire:
Enregistrer un commentaire