سؤال

I am completely to new to Objectify. I am using Objectify for GAE application , I have one interesting question in Objectify filter condition

I am to executing a load method to do some filter like

objectify.load().type(User.class).filter("email", userEmail).first().now();

My Question is, above statement doesn't work until I mark email field in User Entity class as @Index ? Why is this required ? . If we don't put @Index on field, we get null result.

Could some one clarify my doubt, I am little concern about marking my fields as @Index as it might cost space and it(@Index) is one of the candidate to grow data in GAE Datastore.

Thanks to SO post Objectify 4 Filter not working . It helped me to solve my problem.

هل كانت مفيدة؟

المحلول 2

As answered above, your issue isn't actually with Objectify, but rather how the datastore works. You will find it very difficult to work effectively using objectify without understanding the basics of the datastore. You can read the general docs here and specifically about querying here.

The short answer is, that the datastore is only able to match entities to queries if the fields you are querying on are indexed for that entity. Objectify gives you an annotation to achieve this with, consistently across all entities of a given kind.

The reason you must specify each field to index is that indexes have a cost associated with them when you write entities, so having fine grained control is important.

نصائح أخرى

GAE queries only follow indexes. If you don't index a field, it won't show up in a query result set. This is the nature of GAE.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top