Google Appengine - ID为“com.google.appengine.api.datastore.Key:Product(”Potatoe“)”的对象由不同的对象管理器管理

时间:2010-01-19 23:58:19

标签: java google-app-engine jdo

嗨,我正在遇到“由不同的对象管理器管理”的常见错误

我在网上浏览过,找不到符合我问题的解决方案。我从JSP页面调用以下代码

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();
 }
}

错误是在pm.makePersistent(locationInventry);

上引发的

据我所知,我只使用一个持久管理,我在使用后关闭它。谢谢你的帮助。

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)

1 个答案:

答案 0 :(得分:1)

前段时间我遇到了同样的问题,我的内存模糊,我的jdoconfig.xml文件丢失或配置不正确。 查看http://code.google.com/appengine/docs/java/datastore/usingjdo.html了解详情。