I am dusting off my google app-engine / datastore skills ... and getting stuck on something very simple.
As per the example on the GAE documentation I am trying to update an entity as follows:
// persistence and business logic
PersistenceManager pm = PMF.get().getPersistenceManager();
// get it
NickName n = pm.getObjectById(NickName.class, nicknameId);
// update fields
n.givenName = "new name";
n.nickName = "new nickname";
n.timeStamp = new Date();
// close manager to persist changes
pm.close();
This doesn't work (as in the changes are not persisted, but no errors or anything else)!
At the same time I found that if I create a new entity with the same ID the changes get persisted:
// persistence and business logic
PersistenceManager pm = PMF.get().getPersistenceManager();
NickName n = new NickName("new name", "new nickname", new Date());
// set id
n.id = nicknameId;
pm.makePersistent(n);
pm.close();
I have the feeling I already solved this the 1st time I approached app engine and the data-store.
This is what my entity looks like:
@PersistenceCapable
public class NickName {
public NickName(String name, String nickname, Date timestamp) {
this.givenName = name;
this.nickName = nickname;
this.timeStamp = timestamp;
}
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
public String id;
@Persistent
public String givenName;
@Persistent
public String nickName;
@Persistent
public Date timeStamp;
}
Any help appreciated!