@Entity. This annotation identifies the class
Userin the following example as a persistable entity. This will trigger ObjectBox to generate persistence code tailored for this class:
@Transientmarks properties that should not be persisted. In Java
transientproperties will also not be persisted.
@NameInDblets 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.
@Indexto create a database index for the corresponding database column. This can improve performance when querying for that property.
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.
Stringproperties typically require more storage space than scalar values, by default ObjectBox uses a hash index for strings instead.
Stringproperty, specify the index
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.
@Uniqueto enforce that values are unique before an entity is put:
put()operation will abort and throw a
UniqueViolationExceptionif the unique constraint is violated:
@Typein Java/Kotlin or the type attribute on
@Propertyin Dart to override how the value of a property is stored and interpreted in the database.