1
votes

Issue Basics

  • ObjectBox version 2.5.1
  • Reproducibility: [always]

Hi, I am getting this error everytime I want to load my Object even though on saving I checked in the debugger and see that the relation target is not null and everything is saved correctly.

I am having those trhee entity classes

@Entity
data class NetflixCache (
    val results: List<NetflixSearchResult>,
    @Id var objectBoxId: Long?
) {
   var searchParams: ToOne<SearchParams> = ToOne<SearchParams>(this, NetflixCache_.searchParams)
}
@Entity
data class SearchParams(val genrelist: String, 
                        val type: String,
                        val imdbRatingMin: String,
                        val countryId: String,
                        val startYear: Int,
                        val endYear: Int,
                        val offset: Int? = 0,
                        val timeStamp: Long,
                        @Id var id: Long? = null)
@Entity
data class NetflixSearchResult (
    val vtype: String?,
    val img: String?,
    val nfid: Long?,
    val imdbid: String?,
    val title: String?,
    val clist: String?,
    val poster: String?,
    val imdbrating: Double?,
    val synopsis: String?,
    val titledate: Date?,
    val year: Int?,
    var id: Long,
    @Id var objectBoxId: Long?
)

Using this code to save:

val cacheBox = LetsFlixApplication.boxStore.boxFor(NetflixCache::class.java)
val netflixCache = NetflixCache(searchResults, null)
netflixCache.searchParams.target = searchParams
cacheBox.put(netflixCache)

And this code to load:

val cachedResult = cacheBox.all //<-Exception is thrown here

As you can see in debugger when saving, ToOne Object is NOT null: https://ibb.co/s3tdhqP

This is the exact exception message I am getting: ToOne object is null inside com.haenles.letsflix.domain.NetflixCache

1

1 Answers

2
votes

Issue for me was that data class was missing default values as recommended in the doc:

@Entity
data class User(
        @Id var id: Long = 0,
        var name: String? = null
)