我正在使用 hibernate JPA。
我有一个 BasePersonnel
类作为父类(super class),它有一个 filter
:
@Entity
@Table(name = "APP_PERSONEL")
@Filters({
@Filter(name = "authorize",
condition = " 1 = 1 ")
})
public class BasePersonel extends BaseEntity<Integer> {
...
}
它有一个子类:
@Entity
@Table(name = "RTS_PERSONNEL")
@Filters({
@Filter(name = "authorize",
condition = " 2 = 2 ")
})
public class Personnel extends BasePersonel {
...
}
当我使用 hql 在 Personnel
类上运行查询时,两个过滤器(即父类(super class)的过滤器和子类的过滤器)附加到 where
子句。
但我只想将子类过滤器附加到 where
子句。
有什么解决方案可以覆盖父类(super class)过滤器吗?
最佳答案
您可以使用 @Subselect
映射实体时。
@Entity
@Subselect("select * from APP_PERSONEL where authorize = 1")
public class BasePersonel extends BaseEntity<Integer> {
...
}
关于java - 如何覆盖继承类上的 hibernate JPA 过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52950436/