@Id
properties must be var (not val) because ObjectBox assigns the ID after putting a new entity. They also should be of non-null type Long
with the special value of zero for marking entities as new.var
. Otherwise they can not be initialized as described in the relations docs. To avoid null checks use a lateinit modifier. When using a data class this requires the relation property to be moved to the body.build.gradle
file:withContext
: