Reputation: 502
I know only one entity of a specific kind is stored in datastore at a time. How do i retrieve this entity using objectify v4 . what load query/operation will do this. I dont know the ID of entity, so cant query by ID.
I am currently using ofy().load.type(MyObject.class).list();
Is there a better option.
Thank you
Upvotes: 0
Views: 48
Reputation: 13556
If you don't know the key, get the key. Cache it in a static (application-scoped) variable in your app. This is one keys-only query the first time you need the value in an instance.
Then load the value by key directly each time. Make sure you have @Cache
on the entity class. Your load-by-key operation will effectively be a memcache hit every time.
Upvotes: 0
Reputation: 574
If you don't know the Id
of the entity then the other option is to query by the entity's Key
, which can be achieved as follows:
MyObject entity = ofy().load().key(myObjectKey).now();
Upvotes: 0