Currently, soft deletion implementation looks like this:
Parent class
@MappedSuperclass
public abstract class ParentClass {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
private boolean archived = false;
}
Children's class 1
@Entity
@SQLDelete(sql = "UPDATE child_class1 SET archived = 1 WHERE id = ?")
@Where(clause = "is_archived = 'false'")
public class ChildClass1 extends ParentClass {
...
...
}
Child class 2
@Entity
@SQLDelete(sql = "UPDATE child_class2 SET archived = 1 WHERE id = ?")
@Where(clause = "is_archived = 'false'")
public class ChildClass2 extends ParentClass {
...
...
}
As you can see, the SQLDelete and Where clauses are repeated with a slight difference in the query. Is there a way to generalize them and be able to put them in a ParentClass? sort of
@MappedSuperclass
@SQLDelete(sql = "UPDATE <what_would_come_here> SET archived = 1 WHERE id = ?")
@Where(clause = "is_archived = 'false'")
public abstract class ParentClass {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
private boolean archived = false;
}
I tried the above, but hibernation did not apply these annotations to retrieving or deleting entities.
source
share