Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Calling the <code>makePersistent()</code> method doesn't write to the datastore; closing the PersistenceManager or committing your changes does. Since you haven't done this when you run your query, you're getting all objects from the datastore which does not, yet, include the object you just called makePersistent on.</p> <p>Read about object states here: <a href="http://db.apache.org/jdo/state_transition.html" rel="nofollow">http://db.apache.org/jdo/state_transition.html</a></p> <p>There are two ways around this, you can put this inside a transaction since the commit writes to the datastore (keep in mind GAE 5 transaction/entity type limit on transactions) and commit before running your query; Example using transaction...</p> <pre><code>public Collection&lt;MyObject&gt; add(MyObject o) { PersistenceManager pm = PMF.get().getPersistenceManager(); ArrayList&lt;MyObject&gt; list = null; try { Transaction tx=pm.currentTransaction(); try { tx.begin(); pm.makePersistent(o); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } } Query query = pm.newQuery(MyObject.class); List&lt;MyObject&gt; rs = (List&lt;MyObject&gt;) query.execute(); ArrayList&lt;MyObject&gt; list = new ArrayList&lt;MyObject&gt;(); for (MyObject r : rs) { list.add(r); } } finally { pm.close(); } return list; } </code></pre> <p>or you could close the persistence manager after calling makePersistent on o and then open another one to run your query on.</p> <pre><code>// Note that this only works assuming the makePersistent call is successful public Collection&lt;MyObject&gt; add(MyObject o) { PersistenceManager pm = PMF.get().getPersistenceManager(); try { pm.makePersistent(o); } finally { pm.close(); } pm = PMF.get().getPersistenceManager(); ArrayList&lt;MyObject&gt; list = null; try { Query query = pm.newQuery(MyObject.class); List&lt;MyObject&gt; rs = (List&lt;MyObject&gt;) query.execute(); list= new ArrayList&lt;MyObject&gt;(); for (MyObject r : rs) { list.add(r); } } finally { pm.close(); } return list; } </code></pre> <p><strong>NOTE:</strong> I originally said you could just add <code>o</code> to the result list before returning; but that isn't a smart thing to do since in the event that there is a problem writing <code>o</code> to the datastore; then the returned list wouldn't reflect the actual data in the datastore. Doing what I now have (committing a transaction or closing the pm and then getting another one) should work since you have your datastoreReadPolicy set to STRONG.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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