Delete entity bug

Hi,
I reproduced the bug in a sample project
delete_entity_bug.zip (1.0 MB)
I have 3 entities with soft-delete and cascase removal. one of them is based on an abstract class with InheritanceType.TABLE_PER_CLASS

@JmixEntity
@Table(name = "PARENT_ENTITY")
@Entity
open class ParentEntity {
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "parentEntity", cascade = [CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE])
    var children: MutableList<ChildEntity> = NotInstantiatedList()
    ...
}
@JmixEntity
@Table(name = "CHILD_ENTITY", indexes = [
    Index(name = "IDX_CHILD_ENTITY_FORM", columnList = "FORM_ID"),
    Index(name = "IDX_CHILD_ENTITY_PARENT_ENTITY", columnList = "PARENT_ENTITY_ID")
])
@Entity
open class ChildEntity {
    @JoinColumn(name = "PARENT_ENTITY_ID", nullable = false)
    @NotNull
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    var parentEntity: ParentEntity? = null

    @NotNull
    @OnDeleteInverse(DeletePolicy.CASCADE)
    @OnDelete(DeletePolicy.CASCADE)
    @JoinColumn(name = "FORM_ID", nullable = false)
    @OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE], optional = false)
    var form: BaseInspectionForm? = null
    ...
}
@JmixEntity
@Table(name = "SIMPLE_FORM")
@Entity(name = "simpleForm")
open class SimpleForm: BaseInspectionForm() {
    ....
}
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract class BaseInspectionForm {
    ...
}

test scenario:

  1. on ChildEntityListView: Create a childEntity (add a parent and a form to it)
  2. save it
  3. on simpleFormListView: try to delete the form (bug QueryException)
  4. on ChildEntityListView: try to delete the child entity (bug “not null”)
  5. on parentEntityListVeiw: try to delete the parent (it works !)

Bonus:
I believe you that you could make good use of EntityCreateAction.kt. It would be good to have it by in Jmix by default.