Skip to main content

How do I retrieve an object in ObjectBox?

Answer: Use box.get()

  • Retrieves a single object by its ID.
  • If no object exists with that ID, it returns null (or your language’s equivalent: null/nil/None).
  • To fetch several objects at once, use the multi‑get variant (e.g., getMany(...), get(List<Id>), or the platform’s equivalent).

Purpose

The box.get() method looks up and returns one object by its unique ObjectBox ID. Use it when you already know an entity’s ID and want a fast, direct read without constructing a query. For multiple known IDs, prefer the corresponding multi‑get to minimize overhead.

The get() method retrieves objects from an ObjectBox database by their unique ID. Use it to fetch a single object or multiple objects efficiently.

Single-ID Lookup

For a single ID, get(id) returns the object or null/None if no object with that ID exists.

Java example

MyObject object = box.get(1);

Multi-ID Lookup

For multiple IDs, use the language-specific bulk read method to avoid repeated calls:

  • Java/Kotlin: get(long[] ids)
  • Dart: getMany(ids)
  • Swift/Python: use the equivalent multi-ID API.

Java example (multi)

List<MyObject> objects = box.get(new long[]{1, 2, 3});

See also