@Entity
. This annotation identifies the class User
in the following example as a persistable entity. This will trigger ObjectBox to generate persistence code tailored for this class:@Transient
marks properties that should not be persisted. In Java static
or transient
properties will also not be persisted.@NameInDb
lets you define a name on the database level for a property. This allows you to rename the property without affecting the property name on the database level.@Index
to create a database index for the corresponding database column. This can improve performance when querying for that property.String[]
, byte[]
, float
and double
Array<String>
, ByteArray
, Float
and Double
double
and listsList<String>, List<int>, Uint8List, Int8List
List<Person>
. Now, you want to search for all persons with a specific name so you would iterate through the list and check for the name property of each object. This is an O(N) operation and thus doesn't scale well with an increasing number of objects. To make this more scalable you can introduce a second data structure Map<String, Person>
with the name as a key. This will give you a constant lookup time (O(1)). The downside of this is that it needs more resources (here: RAM) and slows down add/remove operations on the list a bit. These principles can be transferred to database indexes, just that the primary resource consumed is disk space.String
properties typically require more storage space than scalar values, by default ObjectBox uses a hash index for strings instead.String
property, specify the index type
:String
, depending on the length of your values, a value-based index may require more storage space than the default hash-based index.String
, VALUE for others).String,
this may require more storage than a hash-based index.@Unique
to enforce that values are unique before an entity is put:put()
operation will abort and throw a UniqueViolationException
if the unique constraint is violated:@Type
in Java/Kotlin or the type attribute on @Property
in Dart to override how the value of a property is stored and interpreted in the database.