Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdated JDO objects will not persist in GWT
    primarykey
    data
    text
    <p>I'm writing a small application using GWT and JDOs to store persistent data. I've been trying to write a function that updates multiple JDO objects based on a query. Its body looks something like this:</p> <pre><code>PersistenceManager pm = getPersistenceManager(); try { q = pm.newQuery(MyObject.class, query); List&lt;MyObject&gt; objects = (List&lt;MyObject&gt;) q.execute(); for (MyObject object: objects) { object.setMyField(newValue); } System.out.println(objects); //[1] } finally { pm.close(); } </code></pre> <p>If I look at the output of the print statement at [1], the objects all have the correctly updated values. When I make an RPC to retrieve the updated objects, however, the values are the same as they were before the update method was called. If I check the datastore in the admin panel, the updates also do not appear.</p> <p>All the other persistence behaviour in my application works fine (e.g. adding new objects, removing objects, querying objects), but I can't seem to figure out what's wrong here. Most of the resources I've found (like <a href="http://code.google.com/appengine/docs/java/datastore/jdo/creatinggettinganddeletingdata.html#Updating_an_Object" rel="nofollow">http://code.google.com/appengine/docs/java/datastore/jdo/creatinggettinganddeletingdata.html#Updating_an_Object</a>) suggest that just having the PersistenceManager open should persist any changes you make to retrieved objects.</p> <p>Any suggestions? I am truly baffled.</p> <p>Thank you!</p> <p><strong>SOLUTION</strong></p> <pre><code>PersistenceManager pm = getPersistenceManager(); try { q = pm.newQuery(MyObject.class, query); List&lt;MyObject&gt; objects = (List&lt;MyObject&gt;) q.execute(); for (MyObject object: objects) { object.setMyField(newValue); JDOHelper.makeDirty(object, myField); } } finally { pm.close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload