objectbox / objectbox/objectbox-java
Detached entities 'ToMany.addAll' throws error
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.6k
- Forks
- 311
- PR merge metrics
- No merged PRs in 30d
Description
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).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at io.objectbox.relation.ToMany.addAll in ToMany.java, then compare its path through ensureBoxes, ensureEntities, ensureEntitiesWithTrackingLists, and trackAdd with the working add loop described in the report. Done means detached entities can be passed to addAll without DbDetachedException, with coverage for the reported reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100