You don't need to implement a Primary Key class. Specify the primary field as a Key and generate the key using KeyFactory:
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.Builder.html You can autogenerate IDs with this method: http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyRange.html You'll probably get more mileage persisting the object in a single entity (treating the datastore more like a key-value store) and using a translation later to turn it into classes to work with than trying to do magic trying to get these classes to persist the way you want them to. In my opinion, you're not sacrificing code readability - you're just moving work around. -- Ikai Lan Developer Programs Engineer, Google App Engine plus.ikailan.com On Tue, Jan 24, 2012 at 1:21 PM, John Goche <johngoch...@googlemail.com>wrote: > > > On Tue, Jan 24, 2012 at 10:08 PM, Matthew Jaggard > <matt...@jaggard.org.uk>wrote: > >> Do you have any good reason to have separate classes rather than one big >> one with all the stuff that's in each? > > > Well, the reason is that I need to reuse class B. For example class A also > has a separate List<B> member. > > >> The main reason I ask is that loading two entities is about twice as >> expensive as loading one twice the size. > > > Tough. I cannot sacrifice code readability here. > > >> If you do have a good reason, you could still persist them as a single >> entity, but I'm not sure how to do this in JDO. In Objectify, you would >> just @Embed one class into the other. >> >> Mat. >> > > Thank you for your reply. > > Looking forward to hearing from someone who would know how to do this in > JDO. > > Regards, > > John Goche > > >> >> On 24 January 2012 20:05, John Goche <johngoch...@googlemail.com> wrote: >> >>> >>> Hello, >>> >>> I have the following classes in a unidirectional 1-1 relationship to >>> each other: >>> >>> class A { >>> >>> B b; >>> >>> // ... more fields >>> >>> } >>> >>> class B { >>> >>> String k; >>> >>> // ... more fields >>> } >>> >>> I want k to be the primary key for class B as well as for class A. >>> How do I accomplish this task? I've been told I need to implement >>> a PK class but don't understand why I would need one. >>> >>> Given I cannot find much information on the BigTable implementation >>> I don't even know how to think about the problem (I understand RDBMS >>> and think of each class as having its own table, although this may be >>> wrong). >>> >>> Thank you for your kind help, >>> >>> John Goche >>> >>> -- >>> 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-java@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. >>> >> >> -- >> 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-java@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. >> > > -- > 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-java@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. > -- 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-java@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.