【发布时间】:2018-12-24 07:23:55
【问题描述】:
我正在尝试在我的 spring - hibernate 项目中实现软删除。
我的计划是使用@SQLDelete 注释覆盖删除方法,并在我的查询中使用休眠@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;
}
}
感谢您的任何帮助:)
【问题讨论】:
标签: java hibernate spring-data