Yes, encoded String keys are designed to be opaque. But it is possible to
compare two Key objects directly:
http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Key.html#compareTo%28com.google.appengine.api.datastore.Key%29

- Jason

On Tue, Sep 1, 2009 at 11:38 PM, Corneliu Paul Lupulet <
corneliu.lupu...@gmail.com> wrote:

> I think I may have found the answer. Even though an encoded key is a
> string, I should use KeyFactory.stringToKey(encodedKeyString) to compare two
> key strings.
>
>
>
>
> On Tue, Sep 1, 2009 at 7:18 PM, Cornel <corneliu.lupu...@gmail.com> wrote:
>
>> Hello!
>>
>> I ran over this problem. I was retrieving a "DbContact" data set
>> simply ordered by
>> encodedKey ascending, and i got this list:
>>
>> [(key agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYm0gMCxIJRGJDb250YWN0GJxIDA
>> name EUROTRIM)
>> , (key agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYnUgMCxIJRGJDb250YWN0GJ5IDA
>> name ANCA ELECTRIC SYSTEMS)
>> , (key agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYn0gMCxIJRGJDb250YWN0GKBIDA
>> name TWIN TRADING)
>> ...............
>>
>> So, apparently
>> "agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYnUgMCxIJRGJDb250YWN0GJ5IDA" <
>> "agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYn0gMCxIJRGJDb250YWN0GKBIDA" (the
>> second and the third entries in the above list)
>>
>> But
>> "agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYnUgMCxIJRGJDb250YWN0GJ5IDA".compareTo
>> ("agljb3NpbnV4NjhyIQsSCkRiQ3VzdG9tZXIYn0gMCxIJRGJDb250YWN0GKBIDA") =
>> 37 > 0, which is opposite!
>>
>> The encodedKey field is defined in the DbContact class as:
>>
>> @PersistenceCapable(identityType = IdentityType.APPLICATION)
>> public class DbContact extends DbEntity {
>>
>>    @PrimaryKey
>>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>>    @Extension(vendorName="datanucleus", key="gae.encoded-pk",
>> value="true")
>>    private String encodedKey;
>>
>> @Persistent
>>    private DbCustomer customer;
>> .......
>>
>> Also, i have a DbCustomer class which is the parent of a DbContact
>> class, defined as:
>>
>> @PersistenceCapable(identityType = IdentityType.APPLICATION)
>> public class DbCustomer extends DbEntity {
>>
>>    @PrimaryKey
>>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>>    @Extension(vendorName="datanucleus", key="gae.encoded-
>> pk",value="true")
>>    private String encodedKey;
>>
>>    @Persistent(mappedBy = "customer")
>>    @Order(extensions = @Extension(vendorName="datanucleus",
>>        key="list-ordering", value="customerProfile desc"))
>>    private List<DbContact> contacts;
>> ..........
>>
>> So what's with this inconsistence? Have any ideas?
>
>
>
>
> --
> Corneliu Paul Lupulet
>
>
>
>
> >
>

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