views:

34

answers:

2

I have the following code [in doPost()] to edit existing record. It does not give any error but record not saved. Any idea? or what is best way to update exsting record based on a single unique field?

     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;
     }
+1  A: 

Persisting an element using directly the PersistenceManager requires you to close the persistance manager, as the GAE doc clearly states.

Riduidel
after pm.makePersistent(u); i have added pm.close();But it still does not work
Manjoor
can you hardcode an edit ,as in, u.Company = "a hardcoded blah company";and test it? (just to eliminate any other logic errors)i just fixed a similar issue with my app and pm.close() really did resolve it
aldrin
I have tried it a few hour back but it does not work
Manjoor
When you say "it does not work", have you got any relevant logs, or is it simply that "nothing happens" ? What do you see when running your code in a debugger on the local datastore (in dev mode) ?
Riduidel
A: 

I have added getter/setter functions and it is working. Still wondering why??? However my problem has been solved.

Manjoor