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.

anyone ? :grimacing:

Hello!

Sorry for the late reply! I will look into this problem and return with an answer soon

Regards,
Dmitry

This problem looks like a known Eclipselink bug. Abstract superclass with TABLE_PER_CLASS inheritance not works well for all types of queries. Removing abstract from BaseInspectionForm solves the problem.

I’ve also noticed that JPA cascades (jakarta.persistence.OneToOne#cascade) are used at the same time with Jmix @OnDelete and @OnDeleteInverse annotations.

  • For soft-delete entities it is better to use Jmix cascade annotations. Such entities are only marked as removed, instead of being deleted from the database by the remove operation. It means that JPA CascadeType.REMOVE will not be triggered.

  • It is better to use plain JPA cascade operations for hard-delete entities only.

And thank you for picker create action idea. I’ve created the issue for it.