Hibernate HQL query does not update the Lucene Index

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:59:36

This is an expected limitation, documented in the Hibernate Search reference.

HQL update statements are interpreted to

  • Generate the batch SQL to perform the operation
  • Invalidate any relevant cache (if using any second level cache)
  • See if pending operations need to be flushed to the database before executing the query

But it's not going to load all potential matches in memory from the database! That would kill performance.

Still Lucene requires the elements in memory, so indeed this is a design limitation and is expected: you should not run mass-update statements on indexed types, but rather iterate on them in memory and apply changes on the entities in a loop.

Loading all entities will be slow as it will need to materialize all data in memory, but that's required to feed Lucene anyway; a good second level cache configuration usually does the trick, or just start the MassIndexer to re-synch it all if changes are massive.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!