Form: exception on change of enum entity property (Kotlin)

Hi,
I receive exception after change property (type: enum) in form.
Property field in form: lookup
Entity and Enum in Kotlin. Cuba Platform v7.2.4

open class Contractor : StandardEntity() {
    @NotNull
    @Column(name = "TYPE_", nullable = false)
    var type: Int? = null

    fun getType(): ContractorType? = type?.let { ContractorType.fromId(it) }

    fun setType(type: ContractorType?) {
        this.type = type?.id!!
    }

    companion object {
        private const val serialVersionUID = -3159358663244063118L
    }
}

enum class ContractorType(private val id: Int) : EnumClass<Int> {

    COMPANY(0),
    SUPPLIER(10),
    CUSTOMER(20);

    override fun getId() = id

    companion object {

        @JvmStatic
        fun fromId(id: Int): ContractorType? = ContractorType.values().find { it.id == id }
    }
}

java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Enum (java.lang.Integer and java.lang.Enum are in module java.base of loader 'bootstrap')
	at com.haulmont.cuba.core.global.MetadataTools.format(MetadataTools.java:144)
	at com.haulmont.cuba.web.gui.components.WebLookupField.generateDefaultItemCaption(WebLookupField.java:129)
	at com.haulmont.cuba.web.gui.components.WebLookupField.generateItemCaption(WebLookupField.java:144)
	at com.vaadin.ui.ComboBox.updateSelectedItemCaption(ComboBox.java:851)
	at com.vaadin.ui.ComboBox.updateSelectedItemState(ComboBox.java:843)
	at com.vaadin.ui.AbstractSingleSelect.setSelectedItem(AbstractSingleSelect.java:353)
	at com.vaadin.ui.AbstractSingleSelect.setSelectedItem(AbstractSingleSelect.java:117)
	at com.vaadin.ui.AbstractSingleSelect.setValue(AbstractSingleSelect.java:151)
	at com.haulmont.cuba.web.gui.components.WebAbstractValueComponent.setValueToPresentation(WebAbstractValueComponent.java:123)
	at com.haulmont.cuba.web.gui.components.WebAbstractValueComponent.setValue(WebAbstractValueComponent.java:95)
	at com.haulmont.cuba.gui.components.data.value.ValueBinder$ValueBindingImpl.sourceValueChanged(ValueBinder.java:316)
	at com.haulmont.bali.events.EventHub.publish(EventHub.java:170) .....

Regards
Marcin

Hi,

You should use instead:

private var type: Int? = null

Otherwise for public properties Kotlin creates additional getter and setter that accept Int, and they mess things up.

Hi,
Thank you very much.

Regards
Marcin