Realm → ObjectBox API Mapping
This quick reference helps you translate common Realm APIs and concepts to ObjectBox equivalents. Use it during migrations together with the full Migration Guide.
Note: Names vary across language bindings (Java/Kotlin, Swift, Dart, Python). When in doubt, check the binding's reference.
Entities / Models
| Concept | Realm | ObjectBox | Reference |
|---|---|---|---|
| Define entity/model | open class Note : RealmObject() (notable exception: RealmObject is an interface in Kotlin!) | @Entity class Note { @Id var id: Long = 0 } | Realm reference | ObjectBox reference |
| Index | @Index | @Index | Realm reference | ObjectBox reference |
| Ignore field | @Ignore | @Transient / binding-specific | Realm reference | ObjectBox reference |
Create / Update
| Task | Realm | ObjectBox | Reference |
|---|---|---|---|
| Insert | realm.write { copyToRealm(obj) } | box.put(obj) | Realm reference | ObjectBox reference |
| Insert many | realm.write { copyToRealm(items) } | box.put(items) (single TX) | Realm reference | ObjectBox reference |
| Update (by ID) | write { findLatest(obj)?.apply{…} } | box.put(obj) (same ID) | Realm reference | ObjectBox reference |
ID behavior: By default, ObjectBox assigns IDs on insert (
id == 0). For assignable IDs, mark the ID as assignable in your binding (e.g.,@Id(assignable = true)in Java/Kotlin).
Read
| Task | Realm | ObjectBox | Reference |
|---|---|---|---|
| Get by ID | realm.query<Note>("id == $0", id).first().find() | box.get(id) | Realm reference | ObjectBox reference |
| Get multiple by IDs | Filter with IN | Java/Kotlin: box.get(long[] ids); Dart: getMany(ids) | Realm reference | ObjectBox reference |
| Query by field | realm.query<Note>("title == $0", "x") | Build a query with conditions (binding API) | Realm reference | ObjectBox reference |
Delete
| Task | Realm | ObjectBox | Reference |
|---|---|---|---|
| Delete by object | write { delete(obj) } | box.remove(obj) | Realm reference | ObjectBox reference |
| Delete by ID | write { findLatest(obj)?.let{ delete(it) } } | box.remove(id) (returns boolean) | Realm reference | ObjectBox reference |
| Delete many | write { delete(query.find()) } | box.remove(ids or collection) (use a TX) | Realm reference | ObjectBox reference |
Relations
| Type | Realm | ObjectBox | Reference |
|---|---|---|---|
| 1:1 | Field reference | Relation field or ID reference | Realm reference | ObjectBox reference |
| 1:n | RealmList<T> | ToMany<T> / relation list | Realm reference | ObjectBox reference |
| m:n | Two RealmLists or link objects | Relation entity or reciprocal ToMany (binding-specific) | Realm reference | ObjectBox reference |
Transactions
| Task | Realm | ObjectBox | Reference |
|---|---|---|---|
| Run in TX | realm.write { … } | store.runInTx { … } | Realm reference | ObjectBox reference |
| Read-only TX | realm.read { … } | Implicit for single ops; explicit TX optional | Realm reference | ObjectBox reference |
Vector / Similarity Search (if applicable)
If your migration targets vector/similarity search, ObjectBox supports on-device vector indexing with HNSW in supported bindings. Check the binding documentation for APIs and constraints.
Reference: ObjectBox reference