我假設你提到的這個「邏輯」訪問其他實體。您需要告訴Hibernate Search,這些實體包含在使用isWarning
方法的實體中。
假設isWarning
方法在名爲MainEntity
的實體中定義,並且它從另一個實體SomeOtherEntity
訪問數據。
在SomeOtherEntity
,你將有關聯的反面:
public class SomeOtherEntity {
@ManyToOne // Or @OneToOne, or whatever
private MainEntity mainEntity;
}
只需添加@ContainedIn,你應該是好的:
public class SomeOtherEntity {
@ManyToOne // Or @OneToOne, or whatever
@ContainedIn
private MainEntity mainEntity;
}
需要注意的是,不幸的是,這個可以有如果SomeOtherEntity
頻繁更新,將會對性能產生重大影響:Hibernate Search將不會準確知道哪些部分SomeOtherEntity
用於MainEntity
,因此即使SomeOtherEntity
中的更改不會影響isWarning
的結果,也會每次SomeOtherEntity
重新編制MainEntity
更改。 A ticket has been filed to address this issue,但它仍然未決。
我們已經嘗試過這個解決方案,但目前爲止還沒有工作:),唯一的方法是有效的,但我們不想使用它。是通過強制休眠保存後再次重新索引obj。 –
我已經多次使用過它,它很有效,所以你可能想要調查。您使用的是哪個版本的Hibernate Search?也許你受到https://hibernate.atlassian.net/browse/HSEARCH-2868的影響? –