Soft delete inheritance

Is it possible to have a @MappedSuperclass entity with trait SoftDelete, and have a concret entity with the SoftDelete behavior without redefine the SoftDelete trait ?

isn’t this exactly what the StandardEntity does?

Yes of course. A trait is just a set of specifically annotated attributes.

I re open this thread because I found a new problem

@JmixEntity
@MappedSuperclass
abstract class BaseEntitySoftDelete : BaseEntity() {
    @DeletedBy
    @Column(name = "DELETED_BY")
    var deletedBy: String? = null

    @DeletedDate
    @Column(name = "DELETED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    var deletedDate: Date? = null
}

@JmixEntity
@Table(
    name = "TEST_BASE_ENTITY_SOFT_DELETE", indexes = [
        Index(name = "IDX_TEST_BASE_ENTITY_SOFT_DELETE_PARENT", columnList = "PARENT_ID")
    ]
)
@Entity
open class TestBaseEntitySoftDelete : BaseEntitySoftDelete() {
    @NotBlank
    @NotEmpty
    @InstanceName
    @Column(name = "NAME", nullable = false)
    @NotNull
    var name: String? = null

    @JoinColumn(name = "PARENT_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    var parent: TestBaseEntity? = null
}

It’s a valid code, compilation is ok, generation is good and soft delete behavior is ok

but If I use it in an other mapped superclass

@JmixEntity
@MappedSuperclass
open class BaseMasterData : BaseEntitySoftDelete() {
    companion object {
        const val NAME = "NAME"
    }

    @NotEmpty
    @Column(name = "CODE", nullable = false)
    @NotNull
    var code: String? = null
}

@JmixEntity
@Table(name = "COM_CIVILITY", uniqueConstraints = [
    UniqueConstraint(name = "IDX_COM_CIVILITY_UNQ", columnNames = ["CODE", "SEARCH_KEY"]),
    UniqueConstraint(name = "IDX_COM_CIVILITY_UNQ_NAME", columnNames = ["NAME", "SEARCH_KEY"])
])
@Entity(name = "com_Civility")
open class Civility : BaseMasterData()

It’s a always valid code, compilation is ok, generation is maybe good but soft delete behavior is ko in test.
The civility Entity works exactly as if soft delete traits was not set !
Not only the civility entity but the TestBaseEntitySoftDelete entity which was not modified don’t work anymore (after a gradle clean) !!

To fix it, I have to copy soft delete traits in BaseMasterData

@JmixEntity
@MappedSuperclass
open class BaseMasterData : BaseEntity() {
    companion object {
        const val NAME = "NAME"
    }

    @JacocoExcludeGenerated([JacocoExcludeType.BUG], "eclipse bug https://forum.jmix.io/t/soft-delete-inheritance/2786/3")
    @DeletedBy
    @Column(name = "DELETED_BY")
    var deletedBy: String? = null

    @JacocoExcludeGenerated([JacocoExcludeType.BUG], "eclipse bug https://forum.jmix.io/t/soft-delete-inheritance/2786/3")
    @DeletedDate
    @Column(name = "DELETED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    var deletedDate: Date? = null
}

Hello @b.vallettedosia

I’ve tried to reproduce the issue using classes you provided, but had no luck.

Please see com.company.bassdkot.user.CommonTest#testSoftDeletion
in attached project:
BadAssignSoftDeleteKotlin_not_reproduced.zip (121.4 KB)

Could you please reproduce the issue on attached or another sample project?

Regards,
Dmitry