简体   繁体   中英

Is this the correct way to set and get a string value using persistance in GAE?

Is this the correct way to set and get a string value using persistance in GAE ?

I'm receiving error :

com.google.appengine.api.datastore.EntityNotFoundException: No entity was found matching the key: jsonString("jsonString")

Adding to store :

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

Key key = KeyFactory.createKey("jsonString", "jsonString");
Entity urlEntity = new Entity("jsonString" , key);
urlEntity.setProperty("urlVal", urlVal);

com.google.appengine.api.datastore.Key urlEntityKey = datastore.put(urlEntity);  

Returning from store :

    Key key = KeyFactory.createKey("jsonString", "jsonString");
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    Entity entity = datastore.get(key);

Please review the below code, also you can find more details on how to use the app engine datastore API by reviewing the documentation here . Also review the notes in the Datastore Overview document.

DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity e = new Entity("data");
e.setProperty("jsonString", "myValue");
Key key = ds.put(e);
Entity entity = ds.get(key);
System .out.println(entity);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM