[1.2.0] [Kotlin] Having TWO ToOne<> relations in one Entity Class. - cannot read back second one.
See original GitHub issueIssue Basics
- ObjectBox version (are using the latest version?): 1.2.0
- Reproducibility: always
Reproducing the bug
Description
If I have an entity with 2 ToOne<> relation fields, one of these fields is not retrieved while reading from boxstore.
@Entity
data class EntityWord(
@Id var id: Long = 0,
var wordId: Int? = 0,
var annotationDetails: ToOne<EntityAnnotation>? = null,
var lineNo: Int? = 0,
var wordNo: Int? = 0,
var audioStart: String? = null,
var audioEnd: String? = null,
var mistakes: ToOne<EntityMistakes>? = null
)
EntityAnnotiation
is an entity with primitive fields.
EntityMistakes
is further an Entity with 3 ToMany<> relations.
In this entity, I can retrieve annotationDetails
but never mistakes
.
I commented annotationDetails
just to check, and THEN I can retrieve mistakes
.
I’ve used the ObjectBox viewer to verify that the mistakes
data does in fact exist in the boxstore.
I cant for the life of me figure out what am i missing in this. Surely, an Entity should be able to support more than ONE ToOne<> relations.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Android Kotlin - Error when using one to many entity relationship
Let's say this class - is "read-only" for Room (it is filled with data ... You have another 2 entities - Card and...
Read more >Micronaut Data - GitHub Pages
Micronaut Data is a database access toolkit that uses Ahead of Time (AoT) ... The above examples return a single instance of an...
Read more >Spring Data R2DBC - Reference Documentation
With Spring Data, declaring those queries becomes a four-step process: Declare an interface extending Repository or one of its subinterfaces and ...
Read more >MapStruct 1.5.3.Final Reference Guide
This is the reference documentation of MapStruct, an annotation processor for generating type-safe, performant and dependency-free bean ...
Read more >JUnit 5 User Guide
Another technical reason for making classes and methods public is to simplify testing on the module path when using the Java Module System....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Trying to reproduce.
Found cause: relation fields inside a data class constructor break the ObjectBox initialization magic. Kotlin byte-code overwrites the values set by ObjectBox.
Background: the transformer adds the relation field initialization code right before any other statements in the constructor body, right after the
super()
call. However, Kotlin byte-code for data classes sets all fields again to the values provided through the constructor params.So
will actually turn into something behaving like:
To work around this, specify relation fields as properties instead:
This should also prevent side-effects when ObjectBox tries to build a data class with box data. -ut
Hey Markus Let me isolate the problem into a smaller kotlin project and send you a link.
I’ll need time till tomorrow… I’ve been away from work and travelling.
Cheers!