objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

object put failed: ID is higher or equal to internal ID sequence: 4 (vs. 1). Use ID 0 (zero) to insert new entities. (OBX_ERROR code 10002) #553

Closed BrinedFish0222 closed 8 months ago

BrinedFish0222 commented 8 months ago

I hope you can help me. Thank you for your help.

An error occurred while put data : Invalid argument(s): object put failed: ID is higher or equal to internal ID sequence: 4 (vs. 1). Use ID 0 (zero) to insert new entities. (OBX_ERROR code 10002)

Basic info

ObjectBox version: 2.2.0 Flutter/Dart SDK: 3.7.0 Reproducible: always Build OS: Windows 11 Deployment device or OS: ALL

code

  Future<ResponseResult<List<CarouselsEntity>>> loadCarousels() async {
    try {
      final response = await HttpManager.getInstance().get(api: Api.loadCarouselsApi);
      ResponseResult<List<CarouselsEntity>> responseResult = ResponseResult.fromJsonPlus(response, (obj) => CarouselsEntity.fromJsonList(obj as List<dynamic>));
      if (responseResult.isSuccessAndHaveData) {
        DatabaseHelper.instance.deleteAll<CarouselsEntity>();
        // error
        DatabaseHelper.instance.saveBatch<CarouselsEntity>(dataList: responseResult.data);
      }
      return responseResult;
    } catch (e) {
      LogUtil.getInstance().error(e.toString());
      return ResponseResult.error();
    }
  }

error msg:

I/flutter (  382): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (  382): │ #0   LogUtil.error (package:iquant/common/utils/log_util.dart:18:12)
I/flutter (  382): │ #1   CarouselsController.loadCarousels (package:iquant/home/carousels/controller/carousels_controller.dart:25:29)
I/flutter (  382): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (  382): │  Invalid argument(s): object put failed: ID is higher or equal to internal ID sequence: 4
greenrobot-team commented 8 months ago

To put new objects, make sure their ObjectBox @Id property is set to 0.

If you need to store an externally provided ID we recommend creating a separate property for that, see the docs for an example.

github-actions[bot] commented 8 months ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.