[appengine-java] Re: Fwd: entity update question

2010-10-14 Thread MatthewAdams
...which, by the way, can be found for JDO 3.0 at
http://jcp.org/aboutJava/communityprocess/mrel/jsr243/index3.html

The section in question here is 12.6.7, p.124, "Make instances
persistent".

--matthew

On Oct 14, 8:34 am, MatthewAdams  wrote:
> I highly recommend a read of the JDO specification.  It's really well
> written, if I don't say so myself... :)
>

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Fwd: entity update question

2010-10-14 Thread MatthewAdams
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  wrote:
> Yes you do.
>
> From:  Vik 
> Reply-To:  
> Date:  Wed, 13 Oct 2010 18:47:33 +0530
> To:  Google App Engine for Java 
> 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.comwww.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 google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com.
> 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.