2017-10-17 34 views

回答

0

我假設你提到的這個「邏輯」訪問其他實體。您需要告訴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,但它仍然未決。

+0

我們已經嘗試過這個解決方案,但目前爲止還沒有工作:),唯一的方法是有效的,但我們不想使用它。是通過強制休眠保存後再次重新索引obj。 –

+0

我已經多次使用過它,它很有效,所以你可能想要調查。您使用的是哪個版本的Hibernate Search?也許你受到https://hibernate.atlassian.net/browse/HSEARCH-2868的影響? –