My entity class:
@Entity(tableName = "student")
data class Student(
@PrimaryKey(autoGenerate = true)
val id: Long,
val name: String,
val age: Int,
val gpa: Double,
val isSingle: Boolean
)
The problem is, since the id
is auto-generated by the Room
database - means no matther what I put for the id
into the constructor it will be overridden anyway, and because it is one of the parameter in the constructor, I have to give the id
every time like this:
val student = Student(0L, "Sam", 27, 3.5, true)
How can I avoid making up the id
so I can just put in the neccessary data like this:
val student = Student("Sam", 27, 3.5, true)