我正在尝试在我的spring-hibernate项目中实现软删除。
我的计划是在查询中使用@SQLDelete
注释覆盖delete方法,并使用休眠@Where
注释过滤逻辑删除的实体。
当我尝试在超类中定义@Where
子句时,我遇到了一些困难。看来这些实体没有从抽象基类继承@Where
子句。
注意:如果我将@Where
注释移至实体类,一切将按预期工作
基础实体类:
@MappedSuperclass
@Where(clause = " IS_DELETED = false")
public abstract class BaseEntity {
@Column(name = "IS_DELETED")
private boolean isDeleted;
public BaseEntity() {
}
public boolean getIsDeleted() {
return this.isDeleted;
}
public void setIsDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}
}
实体类:
@Entity
@Table(name = "Events")
@SQLDelete(sql ="UPDATE events " +
"SET IS_DELETED = true " +
"WHERE id = ?")
public class Event extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@Column(name = "NAME")
private String name;
public Event() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
感谢任何帮助:)
答案 0 :(得分:0)
尝试与@Inherited
一起添加@where
注释。