views:

592

answers:

1

So, I'm using google datastore for my GWT app and my coworker came up with an interesting question that I don't have the answer to. What happens to the set of keys when you delete some of the objects?

For example,

Person.java

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Person {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private Set<Key> favoriteFoods;

    // ...
}

What happens if I delete some of the favoriteFood objects from the datastore? Does the key to that object stay in the set of keys? Is it my responsibility to remove the key from the set?

+3  A: 

Yup. The key will stay there until you remove it. Another gotcha is that you could accidentally stick a Cat key into a list of Dogs - Keys are not typesafe right now. If you want the JDO implementation to do all the book keeping for you you'll need to use owned relationships for now. The docs here imply that this may change in the future. I am not familiar enough with JDO to know how it normally handles unowned relationships. Also be aware that even the owned relationship "magic" happens in the JDO layer, not the datastore itself, so what might look to you like one operation could really be several actual calls to the datastore (for example, a cascading delete situation)

Peter Recore