0

I have a structure:

@Entity
@Table(name = "parent")
@SQLDelete(sql = "UPDATE parent SET is_deleted = true WHERE id1 = ? AND id2 = ?")
@Where(clause = "is_deleted=false")
public class Parent {

    @EmbeddedId
    private SomeEmbeedableId id;

    @Column(name = "is_deleted")
    private boolean isDeleted;

    @ElementCollection
    @CollectionTable(name = "child", joinColumns = {
        @JoinColumn(name = "id1"), @JoinColumn(name = "id2")
    })
    @SQLDelete(sql = "UPDATE child SET is_deleted = true WHERE id1 = ? AND id2 = ?")
    @Where(clause = "is_deleted=false")
    private Set<Child> periods = new TreeSet<>();

The problem is that when I delete the parent JPA uses update as expected to set is_deleted to true. But it also just deletes the embeddable children. I have tried to add @SQLDelete on the @Embeddable type, it doesn't work. Is it possible to achieve soft delete for both parent and children?

Damian
  • 2,930
  • 6
  • 39
  • 61
  • 1
    Issue root cause is likely what is detailed here: https://stackoverflow.com/a/3743149/496099 . You can try the OrderColumn, but otherwise you might want to treat the child as an Entity instead of embeddable. – Chris Aug 24 '23 at 19:50

0 Answers0