【问题标题】:Hibernate define @Where annotation in super classHibernate在超类中定义@Where注解
【发布时间】: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


    【解决方案1】:

    尝试将@Inherited注释与@where一起添加。

    【讨论】:

    • 我收到编译错误 - “注解类型不适用于这种声明”,这是注解的注解。
    • 那么对不起兄弟..检查任何其他方法。
    猜你喜欢
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 2014-02-28
    • 1970-01-01
    相关资源
    最近更新 更多