Thanks for the reply!

I use KeyFactory extensively in my code and I've read almost all the
blog posts on that blog.

It's not a question of yes or no but just for a better solution:-)

On May 6, 10:44 pm, Chau Huynh <cmhu...@gmail.com> wrote:
> Have you tried with 
> KeyFactory?http://code.google.com/appengine/docs/java/javadoc/com/google/appengi...
>
> In this post Max Ross of Google guided how to query with Key, may it help
> you..http://gae-java-persistence.blogspot.com/2010/01/querying-with-key-pa...
>
>
>
> On Thu, May 6, 2010 at 9:10 PM, Kenyth <ken...@gmail.com> wrote:
> > I was partly wrong in the previous post, and finding what was wrong
> > also leads me to the answer to the question asked in the previous
> > post.
>
> > Even using the encoded String key in conjunction with annotated
> > "gae.pk-name" or "gae.pk-id", it is still impossible to make a query
> > with only the key name/id. Below is error messages when you try to do
> > so:
>
> > "<key name/id> is a sub-component of the primary key.  The datastore
> > does not support filtering or sorting by primary key components, only
> > the entire primary key"
>
> > You have to use the complete primary key to do the query, not part of
> > it. So in this case you either make your key name/id the primary key
> > or just use the Key instance as the primary key.
>
> > It turns out using the encoded String key in conjunction with
> > annotated "gae.pk-name" or "gae.pk-id" only provide you with shortcuts
> > to access the key name/id, no other benefits.
>
> > On May 6, 7:30 pm, Kenyth <ken...@gmail.com> wrote:
> > > Is there any way that key name (or pk-name), key id (or pk-id), or
> > > even parent key (or parent-key) can be used in a query regardless of
> > > JPQL or JDQL. I know in the Python edition it's possible (correct me
> > > if I'm wrong).
>
> > > If there's no way to use this kind query, then the power of key name
> > > or id (obviously from the GAE doc you can always benefit from a
> > > annotated parent key) would be very limited *except that you always
> > > use encoded string key in conjunction with annotated "gae.pk-name" or
> > > "gae.pk-id"*.
>
> > > // More to read if you would like to...
> > > From my limited experience with GAE/J, in a normal app key name/id is
> > > a very simple but powerful way to achieve uniqueness. For example,
> > > when you have multiple concurrent requests to create a root entity, in
> > > each request handler you would first check if it exists and then
> > > decide to create a new one or use the existing one. Without using key
> > > name/id it's very hard, if possible, to ensure the uniqueness.
>
> > > Because as far as I know in this case, the global unique key generated
> > > by the datastore is used to decide the transaction commit will succeed
> > > or fail. For the root entities, given the same entity kind and the
> > > same key name/id, the generated key instance will always be the same,
> > > so you can just let the transaction fail or try it again to rewrite
> > > it, but using other fields (say, "name" of a value)  than key name/id,
> > > in all concurrent transactions a new entity will be created and the
> > > transaction commit will succeed since the generated key instance will
> > > always be different from each other.
>
> > > If in this case I would like to always use key name/id I roughly have
> > > three choices:
> > > 1. use Long key or unencoded String key for the entity kind, but the
> > > downside of this is you can't make this entity kind be child of any
> > > entity kind any more according to the official GAE doc;
> > > 2. use Key instance, but the downside is about this question asked in
> > > this post: you may use key name/id to make a query;
> > > 3. use encoded String key in conjunction with annotated "gae.pk-name"
> > > or "gae.pk-id", and the only downside is you have always to use
> > > KeyFactory to convert the encoded string to a Key instance when you
> > > need one (e.g., to establish an unowned relationship)
>
> > > Last, what's described above seems also be true for entities with a
> > > parent. I'm not sure.
>
> > > --
> > > 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-j...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
> > .
> > > For more options, visit this group athttp://
> > 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-j...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@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-j...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine-java+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://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-j...@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