I am new to GAE, and to JDO, I am getting stuck with how to update data.
Using the code below, if I do a getAll()
, then a get()
on an object, then alter an attribute for that object returned by get(), then a getAll()
, the second call to getAll()
returns the original un-altered object.
I tried doing a flush() but that doesn't seem to help. If I restart jetty, the data is not persisted.
public class Notes {
@SuppressWarnings("unchecked")
public List<Note> getAll() {
PersistenceManager pm = PMF.instance().getPersistenceManager();
Query query = pm.newQuery("select from com.uptecs.google1.model.Note order by subject");
return (List<Note>) query.execute();
}
public void add(Note note) {
PersistenceManager pm = PMF.instance().getPersistenceManager();
pm.makePersistent(note);
pm.flush();
}
public Note get(long id) {
PersistenceManager pm = PMF.instance().getPersistenceManager();
return (Note)pm.getObjectById(Note.class, id);
}
public void update(Note note) {
PersistenceManager pm = PMF.instance().getPersistenceManager();
pm.flush();
}
}