Why are my updates not working?

I am new to GAE, and JDO, I am fixated on how to update data.

Using the code below, if I do getAll() and then get() for an object, change the attribute for that object returned by get (), then a getAll() , the second call to getAll() returns the original unmodified object.

I tried to make flash (), but that doesn't seem to help. If I restart the pier, the data is not saved.

 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(); } } 
+4
source share
4 answers

For a good overview, see the following articles:
http://www.ibm.com/developerworks/java/library/j-gaej1/
http://www.ibm.com/developerworks/java/library/j-gaej2/index.html
http://www.ibm.com/developerworks/java/library/j-gaej3.html

2 and 3 are the most important.

 public void add(Note note) { PersistenceManager pm = getPersistenceManagerFactory() .getPersistenceManager(); try { pm.makePersistent(note); } finally { pm.close(); } } 
+3
source

Have you looked at the AppEngine Getting Started Guide ? They have a pretty extensive reference on using the JDO API .

It looks like you are not calling close () after modifying the persistent object.

+1
source

I am not very familiar with JDO, but you do not need to commit () or save () your data before a flash? I think that only these statements will be stored in the database.

0
source

Perhaps actually closing your PersistenceManager might help (ignoring the reasons for using memory!)

0
source

Source: https://habr.com/ru/post/1315553/


All Articles