0

I am building a Compose Desktop application using the IntelliJ IDE and ObjectBox version 3.3.1. I am using the following gradle settings:

val objectboxVersion by extra("3.3.1")

dependencies {
    implementation(compose.desktop.currentOs)

    implementation("io.objectbox:objectbox-windows:$objectboxVersion")
    implementation("io.objectbox:objectbox-kotlin:$objectboxVersion")

I have the following entity class:

@Entity
data class Menu(
    @Convert(converter = LocalDateConverter::class, dbType = Long::class)
    var date: LocalDate = LocalDate.now(),
    
    @Id
    var id: Long = 0
) {
//        I changed this line to use lateinit.
//        var menuItems = ToMany<MenuItem>(this, Menu_.menuItems)
    lateinit var menuItems: ToMany<MenuItem>

}

The MenuItem entity class is defined as:

@Entity
data class MenuItem(
    var name: String = "",

    @Convert(converter = MenuCategoryConverter::class, dbType = String::class)
    var menuCategory: MenuCategory = MenuCategory.None,

    @Id
    var id: Long = 0,
)

Objectbox generates a MenuCursor class which contains the following code:

public long put(Menu entity) {
        LocalDate date = entity.getDate();
        int __id0 = date != null ? __ID_date : 0;

        long __assignedId = collect004000(cursor, entity.getId(), PUT_FLAG_FIRST | PUT_FLAG_COMPLETE,
                __id0, __id0 != 0 ? dateConverter.convertToDatabaseValue(date) : 0, 0, 0,
                0, 0, 0, 0);

        entity.setId(__assignedId);

        attachEntity(entity);
        checkApplyToManyToDb(entity.menuItems, MenuItem.class);
        return __assignedId;
    }

    private void attachEntity(Menu entity) {
        // Transformer will create __boxStore field in entity and init it here:
        // entity.__boxStore = boxStoreForEntities;
    }

As mentioned in the attachEntity function, there should be a private member __boxStore, but there is not. I have tried a similar class as this with an android application, and the lateinit var ToMany field is initialized just after the first field is set. It contains the __boxStore field.

This must be a bug. I can't continue without a resolution on this.

Bruciew
  • 13
  • 5

1 Answers1

0

The solution is to add the following __boxStore field to the Menu class:

@Entity
class Menu(
    @Convert(converter = LocalDateConverter::class, dbType = Long::class)
    var date: LocalDate = LocalDate.now(),

    @Id
    var id: Long = 0
)  {
    var menuItems: ToMany<MenuItem> = ToMany(this, Menu_.menuItems)

    @JvmField
    @Transient
    @Suppress("PropertyName")
    public var __boxStore: BoxStore? = null
}
Bruciew
  • 13
  • 5