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 [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.

Reply via email to