I just took a quick glance at your original post. The only thing I can think
of is that in the original code you don't call getLastLocation so if you
have lazy loading on then that object wouldn't get loaded and perhaps then
the JDO mechanism doesn't realize to get the old object and delete it and
re-assign the new object. In your original code I'd try doing a
getLastLocation call to force the load. I use JDO but I don't use it's
automatic relationship management. I manage all my relationships myself so I
have complete control and don't need to then worry about these issues so in
essence JDO for me is just a simple mapper between Java and the Datastore
and it works very well for me.

On Tue, Jan 4, 2011 at 10:56 AM, yoyo <yoyomo...@gmail.com> wrote:

> I don't really have to do like that. Your solution is more clean and I will
> use it. Thanks.
> But for learning purpose, I've used some others methods.
> I don't know why i can't update a children reference per another.
> In fact, the new object is in the datastore. When I manually delete the
> first reference, the parent now refer his new children. Weird.
>
> 2011/1/4 Stephen Johnson <onepagewo...@gmail.com>
>
>  Why do you have to delete the location entity? Why not just update the
>> current location entity with the new coordinates? That would be much
>> more efficient.
>>
>>
>> On Tue, Jan 4, 2011 at 10:20 AM, yoyo <yoyomo...@gmail.com> wrote:
>>
>>> The update still don't works. I give up.
>>>
>>> I use the "@Persistent(dependent = "true")" and add the delete
>>> instruction when I update the user location, in a transaction.
>>> Now it works, but I think it's not very clean/efficient.
>>>
>>> Have a nice day.
>>>
>>>  public void updateUserLocation(String username, Location newLocation) {
>>>  PersistenceManager pm = PMF.getPersistenceManager();
>>> Transaction tx = pm.currentTransaction();
>>> try {
>>>
>>>    // Get the user and update the location
>>>
>>>    tx.begin();
>>>     POJOUser user = pm.getObjectById(POJOUser.class, username);
>>>    pm.deletePersistent(user.getLastLocation());
>>>    user.setLastLocation(new POJOLocation(newLocation));
>>>    tx.commit();
>>>
>>> } catch (JDOObjectNotFoundException ex) {
>>>
>>> } finally {
>>>
>>>    if (tx.isActive()) {
>>> tx.rollback();
>>>    }
>>>    pm.close();
>>> }
>>>     }
>>>
>>>  @PersistenceCapable
>>> public class POJOUser {
>>>
>>>     /** Primary key */
>>>     @PrimaryKey
>>>     @Persistent
>>>     private String key = null;
>>>
>>>     /** Username */
>>>     @Persistent
>>>     private String username = null;
>>>
>>>     /** Password */
>>>     @Persistent
>>>     private String password = null;
>>>
>>>     /** The last location of the user */
>>>     @Persistent(dependent = "true")
>>>     private POJOLocation lastLocation = null;
>>>      ...
>>> }
>>>
>>>  @PersistenceCapable
>>> public class POJOLocation implements Location {
>>>
>>>     /** Primary key */
>>>     @PrimaryKey
>>>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>>>     private Key key = null;
>>>
>>>     /** X */
>>>     @Persistent
>>>     private Double x = null;
>>>
>>>     /** Y */
>>>     @Persistent
>>>     private Double y = null;
>>>     ....
>>> }
>>>
>>>
>>>   --
>>> 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<google-appengine-java%2bunsubscr...@googlegroups.com>
>>> .
>>> For more options, visit this group at
>>> http://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<google-appengine-java%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://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<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://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.

Reply via email to