title: Google Appengine - Object with id "com.google.appengine.api.datastore.Key:Product("Potatoe")" is managed by a different Object Manager
body: <p>Hi i am hitting the common error "managed by a different object manager"</p>
  
  <p>I have looked around online and not found a solution that fits my problem. I am calling the following code from a JSP page</p>
  
  <pre><code>PersistenceManager pm = PMF.get().getPersistenceManager();
  String query = "SELECT FROM " +Location.class.getName();
  List&lt;Location&gt; locTs = (List&lt;Location&gt;) pm.newQuery(query).execute();
  for (Location location : locTs) {
     location.genRes(pm);
  }
  pm.close();
  return "done";
  </code></pre>
  
  <p>location.genRes </p>
  
  <pre><code> public void genRes(PersistenceManager pm) {
   Key product = this.getLtype(pm).getProductKey();
   String query = "SELECT FROM " + LocationInventry.class.getName() + " WHERE location == '"+key.getId()+"' &amp;&amp; product == '"+product.getId()+"'";
   List&lt;LocationInventry&gt; lvd = (List&lt;LocationInventry&gt;) pm.newQuery(query).execute(); 
   if (lvd.size() == 0 ) {
    LocationInventry locationInventry = new LocationInventry(product, this);
    pm.makePersistent(locationInventry);
   } 
   else {
    lvd.get(0).gen();
   }
  }
  </code></pre>
  
  <p>The error is being thrown on pm.makePersistent(locationInventry);</p>
  
  <p>As far as I can tell I am using only one persistent management and I am closing it after use. Thanks for any help.</p>
  
  <pre><code>Object with id "com.google.appengine.api.datastore.Key:Product("Potatoe")" is managed by a different Object Manager
  org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:375)
  org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:674)
  org.datanucleus.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:694)
  net.sparktank.quilage.datastore.Location.genRes(Location.java:220)
  net.sparktank.quilage.server.MainRunner.genResources(MainRunner.java:239)
  org.apache.jsp.server.generateResources_jsp._jspService(generateResources_jsp.java:45)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
  </code></pre>