- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这就是我的实体的配置方式
@Entity
@Indexed
public class Book{
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, mappedBy = "book")
@IndexedEmbedded
private FrontPage frontPage;
...//other data
}
@Entity
public class FrontPage{
@OneToOne(cascade = {}, fetch = FetchType.EAGER, targetEntity = Book.class)
@JoinColumn(name = "book_id", nullable = false)
@ContainedIn
private Book book;
...//other data
}
这就是我的集成测试的样子
@Test
public void testMerge_RemoveFrontPage() {
insertDataSet("dataset.xml");
Book book = getEntityManager().find(Book.class, 2000L);
//this book instance already have data
book.setFrontPage(null);
dao.merge(book);
//verify after commit
//In database the FrontPage entity reference is removed
}
通过查看数据库,FrontPage 实体已被删除,但在 Book 索引中,我仍然可以看到 FrontPage 数据。
如果我尝试像这样替换 FrontPage 数据,也会发生同样的情况,现在在图书索引中我可以看到两个 FrontPage 数据。
book.setFrontPage(new FrontPage);
通过调试,FullTextIndexEventListener 在日志中记录以下警告,不确定这是否有意义,但我怀疑这可能是一个原因。
org.hibernate.search.event.impl.FullTextIndexEventListener:250 - HSEARCH000024: Unable to reindex entity on collection change, id cannot be extracted: com.x.x.x.FrontPage
不确定这里出了什么问题或者这是预期的行为吗?
我使用的 Hibernate 版本是,
hibernate-search-elasticsearch, hibernate-search-orm = 5.11.4.Final
最佳答案
默认情况下,Elasticsearch 后端的索引几乎是实时的,这意味着更改需要一些时间才能在搜索查询中可见。默认情况下,只需一秒。
您可以通过将属性 hibernate.search.default.elasticsearch.refresh_after_write
设置为 true
来请求在每个索引文档之后刷新。如果您这样做,则在事务提交后更改将立即可见。但是,这会导致性能不佳,因此我不建议在生产中使用它:只需将其用于测试即可。
来自documentation :
Whether to perform an explicit refresh after a set of operations has been executed against a specific index (true or false)
hibernate.search.default.elasticsearch.refresh_after_write false (default)
This is useful in unit tests to ensure that a write is visible by a query immediately without delay. This keeps unit tests simpler. You should not rely on the synchronous behaviour for your production code except in rare cases as Elasticsearch is optimised for asynchronous writes: leave at false for optimal performance.
关于java - Hibernate搜索lucene : Updating index document by removing a child entity makes children entity as orphan in index document,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60318014/
我是一名优秀的程序员,十分优秀!