Thinking out loud here:

When you use that encoded string format you can use it wherever you'd use Key.  
The apparent advantage of using the encoded string format is that your dto 
isn't exposing GAE's Key.  With the encoded string your service layer can be 
oblivious about GAE's Key, without any extra code in your dao; otherwise, to 
hide the Key from the service layer it seems to me that you'd need to convert 
the Key to String via the KeyFactory methods.  Even then it seems a bit dodgy; 
if you're using your persistence layer's dtos in your view layer, which seems 
to be fashionable these days, then your jsp is probably going to want to use 
the primary key, for the value in the selects, check boxes, etc.

So one way to answer your question would be to say that you should (could) use 
String whenever your service layer, or above, uses a dto's primary key.

My question is, what's the down side to using the encoded string in all of your 
dtos?  My inclination is to just forget about Key and use the encoded string 
everywhere.

My other question is, do other databases support String for a primary key?  
I've always used something that's autoincremented, for example, a sequence, and 
those are always longs and their ilk.


James H wrote:
> Rusty, Thanks for the code sample!  How do you decide when to use key
> type of "Key" vs "String"?
> 
> On Nov 4, 1:45 pm, James H <james.hollier...@gmail.com> wrote:
>> Datanucleus, both suggestions worked but I like the "embeddedOnly"
>> best in order to avoid a dummy key on every FK class!
>>
>> Bryce, I no longer get the error above...I just added
>> embeddedOnly="true" to the PersistanceCapable tag in BookFk class.
>> You're right, I could use the collection technique on the FKs but I
>> wonder the pros/cons of such collections on what could be very large
>> collections.  For example, say Baylor with 25,000 members?  Guess its
>> a matter of using "owned" for small Sets versus "unowned" for large
>> Sets of data.  Regardless, your FK pattern will save a whole lot of
>> code management!!!
>>
>> Any further feedback welcome...I'll continue testing!
>>
>> On Nov 4, 12:12 pm, datanucleus <andy_jeffer...@yahoo.com> wrote:
>>
>>
>>
>>>> Needs a PK either way. Pick a field, any field.
>>> Or just set "embeddedOnly" as true ... if you really never want to
>>> persist one of those in its own right- Hide quoted text -
>> - Show quoted text -
> > 

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to