user2213892 user2213892 - 2 months ago 5
Java Question

How and the best way to retrieve a single entity google app engine

I have two entity kinds (Person which has the properties first and last names; Second entity kind is Car which has the properties color and make). Using Java, how do I retrieve one specific entity (say the entity whos id/name is equal to 1) in the most efficient way? I have no built indexes and am using the default indexes Google app engine provides. Looking through google documentation, they provide examples of getting all records within a kind using a loop, but do not show how to get a specific entity.

Answer

Each entity has a key (either autogenerated or provided by you) https://developers.google.com/appengine/docs/java/datastore/overview#Kinds_Keys_and_Identifiers and doing a datastore.get (https://developers.google.com/appengine/docs/java/datastore/entities#Retrieving_an_Entity) is the fastest way to fetch that entity. Any other query will generally be slower.