我假设你提到的这个“逻辑”访问其他实体。您需要告诉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的影响? –