2017-10-17 33 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的影响? –