Chapter 5. Reading Data From Entity Stores
Prev |  | Next

## Chapter 5. Reading Data From Entity Stores

Once you have written objects to an `EntityStore` you can read them back again at a later time. To do this, you use either the primary or the secondary key used by the entity that you want to retrieve.

It is possible to retrieve a single object by using its primary key. You can also retrieve multiple objects in the form of a collection, if the key that you use is capable of referring to more than one object.

## Retrieving a Single Object

To retrieve a single object, you must use an index that is capable of returning just one object. A primary index is one such index, as is a `ONE_TO_ONE` or `ONE_TO_MANY` secondary index.

To retrieve the object, use the index's `get()` method, providing to it the index value that is used by the desired object. For example, the following uses the primary key for the `Inventory` class to retrieve the object with SKU `Trifdess2zJsGi`:

    PrimaryIndex<String,Inventory> inventoryBySku =
        store.getPrimaryIndex(String.class, Inventory.class);
    Inventory inventory = inventoryBySku.get("Trifdess2zJsGi");

Prev | Up | Next
Chapter 4. Writing to Entity Stores | Home | Retrieving Multiple Objects