With version 0.9.14, ObjectBox makes two big steps forward: standalone to-many relations and new build tools. Read on for details and how to upgrade.

Update: 0.9.15 fixes two critical build issues.

Standalone to-many relations

ObjectBox supported to-many relations before, so what are “standalone” to-many relations? Previously, you had to define a to-one relation in the opposite direction and define a to-many as a @Backlink to the to-one relation. This resembles the classic one-to-many (1:N) relationship. In contrast, standalone to-many relations do not depend on a to-one relation. This compares to many-to-many (N:M) relationships. (For full bi-directional N:M support, we will provide @Backlinks to standalone to-many relations in a future version.)

Let’s look at some code with a student / teacher relationship. Students have classes with several teachers and one teacher instructs several students. Thus, we have a N:M relationship here and could model the student class like this:

Note that in entity code, you just need a List/ ToMany property referring to a target entity to have a N:M to-many relation (without additional annotations). For 1:N to-many relations on the other hand, you now need an explicit @Backlink annotation on your List/ ToMany property.

Build system

The second major change is the build system. With our previous version we introduced a new build tool chain for Kotlin builds. This tool chain now replaces the old one that was designed for Java (only). This is also marks the end of our experiment of generating code in entity sources. Some developers did not feel comfortable having a tool generate code in their classes. Also, having a single tool simplifies maintenance for us.

In this version we still offer the old (Java based) Gradle plugin. Consider this as a fallback option in case you have trouble with the new plugin (let us know). To use the legacy plugin, you have to use another ID:
apply plugin: 'io.objectbox.legacy'

How-to upgrade to 0.9.14

This upgrade requires you to make some minor changes. If you are using Kotlin with ObjectBox, you only need to change the plugin ID in your gradle file:
apply plugin: 'io.objectbox'

Java projects should continue to work. However, you can and should delete previously generated code in entities:

  • All @Generated and @Internal annotations (keep the constructors and relation fields)
  • The field  BoxStore __boxStore
  • Assignments to relation fields; for example  ToOne<Customer> customerToOne = new ToOne<>(this, Order_.customer); should become  ToOne<Customer> customerToOne;
  • If you have properties like @Relation Customer customer; you need to replace with a ToOne proxy like this:  ToOne<Customer> customer;. Then, getters can return customer.getTarget() and setter should do customer.setTarget(group). Note that you do not have to init the ToOne field by hand; this is done by ObjectBox.
  • If you have trouble with annotation processor not running, try to add an annotationProcessor/kapt dependency “io.objectbox:objectbox-processor:$objectBoxVersion” manually to your build script

Deleting code is great, isn’t it? Your entity code should look much cleaner now.

PS.: We will update the docs in the upcoming days. Please excuse any discrepancies for now.