ObjectBox: problem opening in Dart a DB file created in Java

700 views Asked by At

I had a running app in Java on Android, and now I try to migrate it to Flutter/Dart. So I re-created the models in Dart and tried the best to match the types with Java. One thing I noticed that can't be exactly matched is model inheritance in Java that's not supported in Dart. For that I duplicated all properties originally in parent class into children classes. My test app first created an empty DB and runs on Linux and Android with basic gets and puts.

Hoping to use the same DB of the Java app, then I copied a DB file that was created and is still being used by the Java app on Android and put it in place for the Dart app. I also copied the model json file so that hopefully the UID's can be matched. Run on Linux, it crashes and reports the following errors, which basically means little to me:

Launching lib/main.dart on Linux in debug mode...
Connecting to VM Service at ws://127.0.0.1:40207/ZJhSLNAdprc=/ws
Error handling 'checkPlatformOverride' custom request: method not available: ext.flutter.platformOverride
Error handling 'checkBrightnessOverride' custom request: method not available: ext.flutter.brightnessOverride
Error handling 'checkIsWidgetCreationTracked' custom request: method not available: ext.flutter.inspector.isWidgetCreationTracked
Error handling 'serviceExtension' custom request: method not available: ext.flutter.inspector.setPubRootDirectories
Lost connection to device.
Exited (sigterm)

Then I tried to launch it on Android, I got exception messages, like

ObjectBoxException (ObjectBoxException: failed to create store: 10501 Cannot change the following flags for Property rightToLeft (6, Bool) (Language) from 4 to 0 (problematic flags: 4). Consider creating a new property instead. Please check the docs on data model migration and UIDs.)

I checked the json file of the Java app, yes, there is the 'flags' field like:

   {
      "id": "6:7344438006121386835",
      "name": "rightToLeft",
      "type": 1,
      "flags": 4
    }

But this property becomes in Dart

    {
      "id": "6:7344438006121386835",
      "name": "rightToLeft",
      "type": 1
    }

The "flags" field got removed for some reason when building the DB routines. Then I checked about other properties, the Java file has many properties that has the flags field. Many of these flags fields got removed in Dart which only keeps a few. I can't find much info on what these flags are, or why they are different between Java and Dart versions, or how to maintain them in Dart so that the DB file can be treated compatibly.

Any suggestion please?

1

There are 1 answers

0
vaind On

That flag (4, not-null) is Java-only and will be "removable" in the future, thus making java->dart existing DB transition possible. It will come in the next objectbox-dart release that also updates core dependencies (c-api, android, ios) - not sure when that is going to happen, yet.