Room database build errors for @Ignore annotation
Hi,
I'm trying to use Room database within a Kotlin project, but I'm having issues with @Ignore annotation.
I have a data class and I'd like to ignore one field. If I add @Ignore to that field, when I build the project I get several errors saying: "Cannot find setter for field" and one: "Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type)."
I've tried to add a new property within User class from GithubBrowserSample and when I build the project I get the same errors.

What happened to this? I am experiencing the same problem.
You should move the @Ignore field outside of the constructor, like this:
@Entity(primaryKeys = ["id"])
data class User(
@field:SerializedName("id")
val id: Int,
@field:SerializedName("name")
val name: String,
@field:SerializedName("age")
val age: Int
) {
@Ignore
val testme: String?
}
@marianperca How do you set the testme field, then? Also, this does still seem like an issue. The documentation is literally incorrect.
In my case the User class is fetched from an API, but the ignored field is not part of the data sent via API, so I have to set it manually when I need that data class.
Right, but doesn't that cause the data class to become mutable? Wouldn't it need to be var testme: String??
I wanted to retain immutability, so I came up with the following solution:
@Entity(primaryKeys = ["id"])
data class User @Ignore constructor(
@field:SerializedName("id")
val id: Int,
@field:SerializedName("name")
val name: String,
@field:SerializedName("age")
val age: Int,
@Ignore
val testme: String?
) {
constructor(id: Int, name: String, age: Int) : this(id, name, age, null)
}
This allows Room to have only a constructor that matches the fields of the entity.
I was able to achieve the same result with @JvmOverloads, as recommended. But surely the docs need clarification.
This issue still persists in latest version of room with KSP room: 2.6.1