A key is a complex object -- you can't query on it using a simple string
literal. Also, you shouldn't be changing an entity's key after it's
persisted -- once a key is set, that key is associated with the entity for
its lifetime.

If you want to query by key, you should use the __key__ syntax and use a Key
object to filter against. I believe you can do this in JDO just as you can
with the low-level API; please let me know if I'm incorrect about this.

- Jason

On Fri, Sep 4, 2009 at 5:08 AM, Corneliu Paul Lupulet <
corneliu.lupu...@gmail.com> wrote:

> I noticed that i can make a query like this:
>
> DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
> Query query = new Query("DbContact");
> query.addFilter("__key__", FilterOperator.GREATER_THAN,
> KeyFactory.stringToKey(a_key_string));
>
> And it works. It fetches the correct results.
>
> Then i also noticed i can do this (locally on my computer; i haven't tested
> this on app-engine yet):
>
> entity.put("__key__", "some value");
> ds.put(entity);
> Using the datastore viewer i can see the object with this property
> (__key__) and the corresponding value i've set.
>
> Then if try a query like this:
> q1.addFilter("__key__", FilterOperator.EQUAL, "some value");
>
> it doesnt' fetch any results!
>
> So can someone explain the mechanism of what is happening over here? :)
>
> One last thing i've noticed:
> If i try the following line in DataViewer --> Query (using GQL):
> SELECT * FROM DbCategory where __key__ > 'a'
>
> I get:
>
> server error(500)
> Server Error
>
> A server error has occurred.
>
> And also, are there any other "reserved" properties like "__key__" i should
> be aware of, or which are useful for special kinds of queries.?
>
> On Fri, Sep 4, 2009 at 2:17 PM, Cornel <corneliu.lupu...@gmail.com> wrote:
> >
> > Hello,
> >
> > How can i make a Query using the lowlevel API, similar to this:
> > select * from Entity where key > <certain_key> ?
> >
> > In JDO i would do something like this:
> > select * from Entity where encodedKey > <a_key_string>
> >
> > where encodedKey is my objects' primary key:
> >
> >    @PrimaryKey
> >    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >    @Extension(vendorName="datanucleus", key="gae.encoded-pk",
> > value="true")
> >    private String encodedKey;
>
>
> --
> 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