簡體   English   中英

如何在繼承的類上覆蓋休眠 JPA 過濾器?

[英]How to override hibernate JPA filter on inherited class?

我正在使用休眠 JPA。

我有一個BasePersonnel類作為具有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類上運行查詢時,兩個過濾器(即超類的過濾器和子類的過濾器)都附加到where子句。 但我只想將子類過濾器附加到where子句。

有什么解決方案可以覆蓋超類過濾器嗎?

您可以在映射實體時使用@Subselect

@Entity
@Subselect("select * from APP_PERSONEL where authorize = 1")
public class BasePersonel extends BaseEntity<Integer> {
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM