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?