You can't filter by the name component of the key because the datastore
doesn't support this.  You can only filter by the entire key.  Why can't you
create the key by hand?  KeyFactory.Builder should have everything you need
to do this.

2009/9/6 Kriván Bálint <bal...@krivan.hu>

>
> Hi!
>
> I've the following Entity:
>
> ====
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Document implements Serializable {
>
>        @PrimaryKey
>        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>        @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value
> = "true")
>        private String encodedKey;
>
>        @Persistent
>        @Extension(vendorName = "datanucleus", key = "gae.pk-name", value =
> "true")
>        private String id;
>
> [...]
>
> }
> ====
>
> I would like to create a query filtered by "id", but it doesn't work.
> How can I make this work? Thanks for your help!
>
> My try was the following:
>
> ====
> Query query = pm.newQuery(Document.class);
> query.setFilter("id == param");
> query.declareParameters("String param");
>
> try {
>        List<Document> results = (List<Document>) query.execute(id);
>        if (results.iterator().hasNext()) {
>                for (Document d : results) {
>                        // do something with the Document.
>                        // throw new RuntimeException(d.getTitle());
>                }
>        } else {
>                // ... no results ...
>        }
> } catch (Exception ex) {
>        ex.printStackTrace();
> } finally {
>        query.closeAll();
> }
> ====
>
> I know I've could get the object by Key, but there's a hierarchy in
> Documents, so I can't create the key by hand.
>
> Thanks!
> >
>

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