2

I'm having issues creating @Relation. I previously was using a complicated query to handle M:N, but I wanted to try the simpler @Relation and rely on ids. However, I get an error whenever I extend or embed the @Relation class. This works:

@Entity(tableName = "meta",
foreignKeys = [ForeignKey(
    entity = FolderEntity::class,
    parentColumns = ["id"],
    childColumns = ["parentId"],
    onDelete = CASCADE)],
indices = [
    Index(value = ["uri"], unique = true),
    Index(value = ["documentId"], unique = true),
    Index(value = ["parentId"])])
open class MetadataEntity {
@PrimaryKey(autoGenerate = true)
    var id: Long = 0
    ...
}

@TypeConverters(MetadataResult::class)
class MetadataResult : MetadataEntity() {
   var keywords: List<String>? = null
   var parentUri: String? = null

   @TypeConverter
   fun fromGroupConcat(keywords: String?): List<String>? = keywords?.split(",")
}

However, this does not work:

data class MetadataXmp(
   @Embedded
   val metadata:MetadataEntity,
   @Relation(
        parentColumn = "id",
        entityColumn = "metaId",
        projection = ["subjectId"],
        entity = SubjectJunction::class)
   var subjectIds: List<Long> = Collections.emptyList(),

   @Relation(
        parentColumn = "parentId",
        entityColumn = "id",
        projection = ["documentUri"],
        entity = FolderEntity::class)
   var parentUris: List<String> = Collections.emptyList())

Please note that the varying object type (class, data class, etc) is just the state of disarray of my attempts. I have tried various versions of extension with MetadataXmp or embedding, abstract, data class, etc. I don't seem to be able to introduce @Relation.

3 Answers 3

4

I was facing a similar Error message, for me the issue was that I had not declared the enity in the Database class but I had Annotated the pojo, Posting answer as it might help somebody with similar problem.

Sign up to request clarification or add additional context in comments.

1 Comment

saved me bro, thanks lots. I had encluded the wrong entity class on the entities array
1

The error is actually related to @RawQuery:observedEntities. I was observing the result POJO instead of the underlying @Entity. The error message simply points to the POJO which is misleading. Google is looking at improving the error message.

Comments

0

I was facing the same issue while implementing the room DB in our application. but in my case room DB version is 2.2.6 when I increase to the latest version 2.3.0 solved my issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.