Hibernate @Where没有强制执行@MappedSuperClass实体

时间:2014-09-23 03:06:29

标签: java hibernate jpa entity where

对于从eclipse链接迁移到hibernate,我在@AdditionalCriteria @MappedSupperClass级别的Hibernate中寻找等效的eclipse链接注释BaseEntity,以过滤所有实体中的逻辑删除记录这个BaseEntity

我找到了@Where注释。但是,这仅适用于Entity级别,而不适用于BaseEntity。如果有可能添加此内容或任何其他Hibernate注释来过滤BaseEntity,请与我们联系。

@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 个答案:

答案 0 :(得分:0)

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

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