打开数据库时出错 'objectbox':在实体 "Album"、属性 "artistId" 中:缺少 virtualTarget

Error opening the database 'objectbox': In entity "Album", property "artistId": missing virtualTarget

我正在尝试在 Windows 上使用 docker 设置同步服务器,但我收到“打开数据库时出错 'objectbox':在实体“相册”中,属性 “artistId”:在 运行 此命令之后缺少 virtualTarget:docker run --rm -it -v %cd%:/data --publish 127.0.0.1:9999:9999 --publish 127.0.0.1:9980:9980 --user=0 objectboxio/sync:21.5.14-server --model /data/objectbox-model.json --unsecured-no-authentication --browser-bind 0.0.0.0:9980

这是我的 model.json:

{
  "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
  "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
  "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
  "entities": [
    {
      "id": "1:5798298704074413534",
      "lastPropertyId": "3:47976863942241076",
      "name": "Album",
      "flags": 2,
      "properties": [
        {
          "id": "1:2766334915860083274",
          "name": "id",
          "type": 6,
          "flags": 1
        },
        {
          "id": "2:7127912550768516753",
          "name": "title",
          "type": 9
        },
        {
          "id": "3:47976863942241076",
          "name": "artistId",
          "indexId": "1:5025869377329785302",
          "type": 11,
          "flags": 1548,
          "relationTarget": "Artist"
        }
      ],
      "relations": []
    },
    {
      "id": "2:3610255661907547309",
      "lastPropertyId": "2:866597986492054995",
      "name": "Artist",
      "flags": 2,
      "properties": [
        {
          "id": "1:8211995468434539608",
          "name": "id",
          "type": 6,
          "flags": 1
        },
        {
          "id": "2:866597986492054995",
          "name": "name",
          "type": 9
        }
      ],
      "relations": []
    },
    {
      "id": "3:7162260877203742605",
      "lastPropertyId": "5:3077441054734333760",
      "name": "Customer",
      "flags": 2,
      "properties": [
        {
          "id": "1:1334004294809772177",
          "name": "id",
          "type": 6,
          "flags": 1
        },
        {
          "id": "2:8500254104736767378",
          "name": "firstName",
          "type": 9
        },
        {
          "id": "3:1261795948739215169",
          "name": "lastName",
          "type": 9
        },
        {
          "id": "4:8863096110280655355",
          "name": "phone",
          "type": 9
        },
        {
          "id": "5:3077441054734333760",
          "name": "email",
          "type": 9
        }
      ],
      "relations": []
    },
    {
      "id": "4:720703670162855056",
      "lastPropertyId": "4:5690325342466026680",
      "name": "Invoice",
      "flags": 2,
      "properties": [
        {
          "id": "1:1570181203114245602",
          "name": "id",
          "type": 6,
          "flags": 1
        },
        {
          "id": "2:4307795986019697116",
          "name": "date",
          "type": 10
        },
        {
          "id": "3:5403205385433436440",
          "name": "total",
          "type": 8,
          "flags": 4
        },
        {
          "id": "4:5690325342466026680",
          "name": "customerId",
          "indexId": "2:8233264265765179610",
          "type": 11,
          "flags": 1548,
          "relationTarget": "Customer"
        }
      ],
      "relations": []
    },
    {
      "id": "5:2124535126347251014",
      "lastPropertyId": "5:600965215010068015",
      "name": "InvoiceItem",
      "flags": 2,
      "properties": [
        {
          "id": "1:3893797232755033190",
          "name": "id",
          "type": 6,
          "flags": 1
        },
        {
          "id": "2:3484774170370690529",
          "name": "unitPrice",
          "type": 8,
          "flags": 4
        },
        {
          "id": "3:5271985023292199596",
          "name": "quantity",
          "type": 5,
          "flags": 4
        },
        {
          "id": "4:7557084807279778428",
          "name": "invoiceId",
          "indexId": "3:1116397924317199080",
          "type": 11,
          "flags": 1548,
          "relationTarget": "Invoice"
        },
        {
          "id": "5:600965215010068015",
          "name": "trackId",
          "indexId": "4:1677643892085601951",
          "type": 11,
          "flags": 1548,
          "relationTarget": "Track"
        }
      ],
      "relations": []
    },
    {
      "id": "6:828952092407258806",
      "lastPropertyId": "5:8273078892571453738",
      "name": "Track",
      "flags": 2,
      "properties": [
        {
          "id": "1:4902677122121855061",
          "name": "id",
          "type": 6,
          "flags": 1
        },
        {
          "id": "2:1219132270817494543",
          "name": "name",
          "type": 9
        },
        {
          "id": "3:3607878157603664853",
          "name": "unitPrice",
          "type": 8,
          "flags": 4
        },
        {
          "id": "4:2322328496342192994",
          "name": "stock",
          "type": 5,
          "flags": 4
        },
        {
          "id": "5:8273078892571453738",
          "name": "albumId",
          "indexId": "5:1459310406895714984",
          "type": 11,
          "flags": 1548,
          "relationTarget": "Album"
        }
      ],
      "relations": []
    }
  ],
  "lastEntityId": "6:828952092407258806",
  "lastIndexId": "5:1459310406895714984",
  "lastRelationId": "0:0",
  "lastSequenceId": "0:0",
  "modelVersion": 5,
  "modelVersionParserMinimum": 5,
  "retiredEntityUids": [],
  "retiredIndexUids": [],
  "retiredPropertyUids": [],
  "retiredRelationUids": [],
  "version": 1
}

类:

@Sync
@Entity
public class Album {
    @Id
    public long id;
    public String title;
    //public long artistId;
    public ToOne<Artist> artist;
    @Backlink(to = "album")
    public ToMany<Track> tracks;

    public Album(){}

    public Album(long id, String title, long artistId){
        this.id = id;
        this.title = title;
        this.artist.setTargetId(artistId);
    }
}
@Sync
@Entity
public class Artist {
    @Id
    public long id;
    public String name;
    @Backlink(to = "artist")
    public ToMany<Album> albums;

    public Artist(){}

    public Artist(long id, String name){
        this.id = id;
        this.name = name;
    }
}

我基于 https://docs.objectbox.io/relations 创建了我的实体,我是 objectbox 的新手,如果错误很明显,我深表歉意。

编辑:我把 gradle 文件放在这里以防万一我在那里遗漏了什么。

buildscript {
    ext.objectboxVersion = '2.9.2-RC4'
    repositories {
        google()
        //jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        //jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
plugins {
    id 'com.android.application'
    id 'io.objectbox.sync'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.mediastore"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    implementation "io.objectbox:objectbox-sync-android:$objectboxVersion"
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

至少为 Java 版本 2.9.2-RC4 使用 ObjectBox,它从模型 JSON 文件中删除了一些与 Sync 不兼容的标志。