The tutorial below states:
An entity class must have an open or protected constructor without arguments ... An interface cannot be assigned as an object ... An entity class must not be final. No methods or constant variables of an instance of an entity class can be final.
Kotlin classes follow the JavaBeans convention for setters / getters.
If your ORM has requirements as stated above, you really need to specify open for the class and its methods:
open class Person(open val name: String = "", open val age: Int = 0)
The default values ββfor all constructor options allow Kotlin to generate an additional empty constructor. Alternatively, you can specify it as a secondary constructor:
open class Person(open val name: String, open val age: Int) { constructor() : this("", 0) }
Note that open val creates a closed end field and an open getter. If this is not enough, use annotations like @JvmField open val name .
ORMs such as the ones you use have additional friction with the Kotlin code due to the dubious design patterns they use (for example, to make everything non-final).
A good option is to use a Kotlin-specific ORM. For example, Exposed is supported by JetBrains and is used for some of its products, which speaks for itself. Another option is Ebean , which officially supports Kotlin (thanks @johnp)
source share