我有以下代码[在doPost()]中编辑现有记录。它不会给出任何错误但记录未保存。任何的想法?或基于单个唯一字段更新exsting记录的最佳方法是什么?
if(sAction.compareToIgnoreCase("S")==0)
{
String email = req.getParameter("Email");
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(SMSUser.class);
query.setFilter("Email == pEmail");
query.declareParameters("String pEmail");
List<SMSUser> users = (List<SMSUser>) query.execute(email);
if(!users.isEmpty())
{
Iterator it = users.iterator();
SMSUser u = (SMSUser) it.next();
u.ContractPerson = req.getParameter("ContractPerson");
u.Company = req.getParameter("Company");
u.Address = req.getParameter("Address");
u.Phone = req.getParameter("Phone");
u.Aid = req.getParameter("Aid");
u.Pin = req.getParameter("Pin");
u.SenderId = req.getParameter("SenderId");
u.Url = req.getParameter("Url");
u.Operater = Integer.parseInt(req.getParameter("Operater"));
pm.makePersistent(u);
}
return;
}
答案 0 :(得分:1)
直接使用PersistenceManager保留元素需要您关闭持久性管理器,如the GAE doc clearly states。
答案 1 :(得分:0)
我添加了getter / setter函数,它正在运行。还在想为什么??? 但是我的问题已经解决了。