Room Database error with Kotlin Data Class

The problem in your case is, that if you have nullable values Kotlin will generate several constructors for each possible constructor.

That means that you have to define a default constructor and fill it with default values.

If you want to have another one which should be ignored you should make sure to use the parent constructor with all those parameters.

Example:

@Entity(tableName = "inspections")
data class Inspection(
@SerializedName("id")
var id: Int = 0,

@PrimaryKey
@SerializedName("guid")
var guid: String = "",

@SerializedName("score")
var score: Double = 0.0,

@SerializedName("notification_sent_at")
var notificationSentAt: Date = Date(),

var wasUploaded: Boolean = false)  {

@Ignore
constructor() : this(0, "", 0.0, Date(), false)
}

In this case only two constructors will be generated "under the hood". If you have nullable values you will have all possible constructors available.

Example:

data class Test(var id: Int = 0, var testString: String? = null, var testBool : Boolean? = null) {
   constructor(0)
} 

generates

constructor(var id:Int)
constructor() : this(0)
constructor(var id:Int, var testString: String)
constructor(var id:Int, var testBool: Boolean) 
constructor(var id:Int, var testString: String, var testBool : Boolean)
// .. and so on

Since you'r looking for an official documentation, you may want to look at Overloads Generation.

After testing your class which works flawlessly i found in another post that you have to check if you used apply plugin: 'kotlin-kapt' in your Gradle.

Double check that you've valid type converters for your Date class. I wrote that issue longer time ago.

After recoding your stuff above it worked just fine by adding a UserPermissions class like that:

data class UserPermissions(var permissionid: String) 

Edit: After using your UserPermission class everything worked just fine. Please take care if you use the proper import (util.Date instead of sql.Date for example).

Another problem is that your using an old very buggy library of room.

The current version (while writing this) is

implementation "android.arch.persistence.room:runtime:1.0.0-beta2"
kapt "android.arch.persistence.room:compiler:1.0.0-beta2"
implementation "android.arch.persistence.room:rxjava2:1.0.0-beta2"

I wrote an issue long time ago


The issue was extremely difficult to debug and harder to reproduce, but I found the issue. I was using an @Embedded object, but the result that was going in was actually a List of that object. This was giving trouble to the automatic Embed task, and there wasn't a perfect Converter that could be written for it.

@SerializedName("range_choices")
@Embedded
var rangeChoices: List<RangeChoice>? = null,

I had to annotate that with @Ignore and instead, I'll be saving the results of this list to its own table, now the new table range_choices.