objectbox / objectbox/objectbox-java

Detached entities 'ToMany.addAll' throws error

未关闭
#412 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
Java
星标
4.6k
派生
311
PR 合并指标
30 天内没有已合并 PR

描述

Issue Basics

  • ObjectBox version 1.4.4
  • Reproducibility: Always

Reproducing the bug

When creating entities (for inserting into ObjectBox), the ToMany field will throw this error if I use .addAll(list) it works if I use .add(entity) in a loop over the list.

Code

entity.bodyparts.addAll(bodyparts)

Logs & stackstraces

io.objectbox.exception.DbDetachedException: Cannot resolve relation for detached entities at io.objectbox.relation.ToMany.ensureBoxes(ToMany.java:144) at io.objectbox.relation.ToMany.ensureEntities(ToMany.java:184) at io.objectbox.relation.ToMany.ensureEntitiesWithTrackingLists(ToMany.java:155) at io.objectbox.relation.ToMany.trackAdd(ToMany.java:230) at io.objectbox.relation.ToMany.addAll(ToMany.java:264)

Entities

lateinit var bodyparts: ToMany<BodypartEntity>

Misc

As mentioned above, the issue seems to be with .addAll specifically, whereas .add does work. The issue happens with detached entities, not using @Id(assignable = true).

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 ToMany.java 中的 io.objectbox.relation.ToMany.addAll 开始,然后将其经过 ensureBoxes、ensureEntities、ensureEntitiesWithTrackingLists 和 trackAdd 的路径,与报告中描述的可正常工作的 add 循环进行比较。当 detached entities 可以传递给 addAll 且不会抛出 DbDetachedException,并且已覆盖报告中的复现案例时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, kotlin
领域
database
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。