Since you've created a new kind (Membership) to model the relationship
between Person and Group, I'm a bit confused on why you're using a
relationship between Group and Membership. Shouldn't Group and Membership be
independent?
class Person {
...
}
class Group {
...
}
class Membership {
Key key; // key name is concatenated IDs of Person and Group
...
}
Solution 1 is less work and less code but my feeling is that, as your code
gets older, it could become more of a problem, especially if other
programmers start committing and don't understand how or why you're
concatenating the IDs to store membership information. If this is likely, I
would opt for solution 2.
If you go ahead with solution 1, you can take advantage of one of the more
recent 1.2.5 features, allocateIds(), which allows you to set aside one or
more IDs for entities yet to be created. It's only exposed in the low-level
API at this point:
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/DatastoreService.html
- Jason
On Sun, Sep 6, 2009 at 11:18 PM, Sam Walker <[email protected]> wrote:
> In 1, another problem is that I may not know the Keys of A and B at the
> point of creation. For example, lets say I am doing something like this:
>
> class Person {
> }
>
> class Group {
> @Persistent(mappedBy = "group")
> ArrayList<Membership> memberships;
> }
>
> class Membership {
> Key person;
> Group group;
> }
>
>
> Now I would do:
> Group g = new Group();
> while(...) {
> Membership m = new Membership();
> g.memberships.add(m);
> }
> pm.makePersistent(g);
>
> Now, when I create membership, I dont have the Group key (I do have the
> person key), I can't really use it to create a new derived key for
> membership. Or am I missing something?
>
>
> On Sun, Sep 6, 2009 at 11:04 PM, Sam Walker <[email protected]>wrote:
>
>> Lets say there is a relationship between Entities A and B, and I want to
>> model it with Entity C.
>>
>> Two ways:
>> 1. Use concatenated Key of A and B for Key of C. Data model will ensure
>> there are no duplicates.
>> 2. Use autogenerated Key and make sure you do not duplicate A B
>> relationship in code.
>>
>> Which one would you choose? In 1, is a simple concatenation the best way
>> to go about it?
>>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---