Incorrect, Vik. You do not need to call pm.makePersistent(e) in order to save changes made to an already persistent object. You use makePersistent(..) to cause new instances to become persistent, to merge detached instance state into the persistence context, or to attach detached instances into the persistence context in place.
The act of changing the state of a persistence capable instance marks the instance as dirty, which JDO will then flush at or before the commit of the transaction governing your operation. Calling pm.makePersistent(x) on an instance x that is already persistent is a no-op. If x is detached and you want to merge the changes incurred while detached into the persistent object graph, then do the following: Employee persistentEmployee = pm.makePersistent(detachedEmployee); The PersistenceManager will take the detachedEmployee, find its persistent counterpart by id (persistentEmployee), apply any changes found in detachedEmployee to persistentEmployee, then return persistentEmployee. This happens assuming that the option javax.jdo.option.CopyOnAttach is true. If false and the PM has no Employee with that oid currently in the persistence context, then detachedEmployee itself transitions to persistent-dirty and is itself returned. If false and the PM already has an Employee with the same oid in the persistence context, then a JDOUserException will be thrown. I highly recommend a read of the JDO specification. It's really well written, if I don't say so myself... :) HTH, Matthew JDO Expert Group Member On Oct 13, 1:56 pm, Cyrille Vincey <[email protected]> wrote: > Yes you do. > > From: Vik <[email protected]> > Reply-To: <[email protected]> > Date: Wed, 13 Oct 2010 18:47:33 +0530 > To: Google App Engine for Java <[email protected]> > Subject: [appengine-java] Fwd: entity update question > > Hie > > I do for create like > > try{ > Employee e = new Employee(); > pm.makePersistent(e); > > }finally(){ > pm.close(); > } > > For update case I am getting the entity by id and updating one of the > attribute like > Employee e = pm.getObectById(empPK, Employee.class); > e.setSalary(1000); > > the question is do i need to call the below statement in this case as well? > pm.makePersistent(e) > > Thankx and Regards > > Vik > Founderwww.sakshum.com<http://www.sakshum.com>www.sakshum.blogspot.com<http://www.sakshum.blogspot.com> > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/google-appengine-java?hl=en. -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
