Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating "nested" objects with JDO on Google App Engine
    text
    copied!<p>I'm having trouble figuring out the proper way to update "nested" data using Google App Engine and JDO. I have a <a href="http://pastebin.com/d386a4dcd" rel="nofollow noreferrer">RecipeJDO</a> and an <a href="http://pastebin.com/d386a4dcd" rel="nofollow noreferrer">IngredientJDO</a>.</p> <p>I want to be able to completely <strong>replace the ingredients</strong> in a given recipe instance with a new list of ingredients. Then, when that recipe is (re)persisted, any previously attached ingredients will be deleted totally from the datastore, and the new ones will be persisted and associated with the recipe.</p> <p>Something like:</p> <pre><code> // retrieve from GAE datastore RecipeJDO recipe = getRecipeById(); // fetch new ingredients from the user List&lt;IngredientJDO&gt; newIngredients = getNewIngredients(); recipe.setIngredients(newIngredients); // update the recipe w/ new ingredients saveUpdatedRecipe(recipe); </code></pre> <p>This works fine when I update (detached) recipe objects directly, as returned from the datastore. However if I <strong>copy</strong> a RecipeJDO, then make the aforementioned updates, it ends up appending the new ingredients, which are then returned along with the old ingredients when the recipe is then re-fetched from the datastore. (Why bother with the copy at all? I'm using GWT on the front end, so I'm copying the JDO objects to DTOs, the user edits them on the front end, and then they are sent to the backend for updating the datastore.)</p> <p>Why do I get different results with objects that I create by hand (setting all the fields, including the id) vs operating on instances returned by the PersistenceManager? Obviously JDO's bytecode enhancement is involved somehow. </p> <p>Am I better off just explicitly deleting the old ingredients before persisting the updated recipe?</p> <p>(Side question- does anyone else get frustrated with ORM and wish we could go back to plain old RDBMS? :-)</p>
 

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