休眠@Where未在实体@MappedSuperClass强制执行

2022-09-04 04:52:46

为了从 eclipse link 迁移到 Hibernate,我正在寻找相当于 Hibernate 中的 eclipse link annotation at level,以过滤来自扩展此内容的所有实体的逻辑删除记录。@AdditionalCriteria@MappedSupperClassBaseEntityBaseEntity

我找到了注释。但是,这仅适用于级别,而不适用于基本实体。请让我知道,如果有任何可能性添加这个或任何其他休眠注释来过滤。@WhereEntityBaseEntity

@MappedSuperclass
@Where(clause = "DEL_IND = 0")  // DOES NOT WORK
public abstract class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column(name = "DEL_IND")
    private boolean deleted = Boolean.FALSE;

    public boolean getDeleted() {
        return deleted;
    }

    public void setDeleted() {
        this.deleted = Boolean.TRUE;
    }

}


@Entity
@Table(name = "PERSON")
@Where(clause = "DEL_IND = 0")  // THIS WORKS BUT NEEDS TO BE REPEATED IN ALL ENTITIES
public class Person extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    @Column(name = "PERSON_ID")
    private Integer id;

    @Column(name = "LAST_NAME")
    private String lastName;

    @Column(name = "FIRST_NAME")
    private String firstName;

    --------------------
    getters & setters
    --------------------
    --------------------
}

答案 1

您可以为此打开休眠 JIRA 问题。唯一的解决方法是手动将批注添加到所有实体或使用筛选器。@Where

使用过滤器,您可以选择动态启用/禁用它们,这很有用,因为您有时可能想要获取已删除的项目。


答案 2

推荐