Hi i am hitting the common error "managed by a different object manager"
I have looked around online and not found a solution that fits my problem. I am calling the following code from a JSP page
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "SELECT FROM " +Location.class.getName();
List<Location> locTs = (List<Location>) pm.newQuery(query).execute();
for (Location location : locTs) {
location.genRes(pm);
}
pm.close();
return "done";
location.genRes
public void genRes(PersistenceManager pm) {
Key product = this.getLtype(pm).getProductKey();
String query = "SELECT FROM " + LocationInventry.class.getName() + " WHERE location == '"+key.getId()+"' && product == '"+product.getId()+"'";
List<LocationInventry> lvd = (List<LocationInventry>) pm.newQuery(query).execute();
if (lvd.size() == 0 ) {
LocationInventry locationInventry = new LocationInventry(product, this);
pm.makePersistent(locationInventry);
}
else {
lvd.get(0).gen();
}
}
The error is being thrown on pm.makePersistent(locationInventry);
As far as I can tell I am using only one persistent management and I am closing it after use. Thanks for any help.
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)