According to the documentation:
Quote:
By default, every time an object is inserted, updated or deleted through Hibernate, Hibernate
Search updates the according Lucene index
This makes much sense. However, I noticed that the Lucene index is not updated when I'm deleting entities from my code.
I tried using both CriteriaDelete and NativeNamedQuery methods but in both cases the index is not updated. I haven't tried the EntityManager.remove method but I don't want to use it because it is very limited.
Code:
public void removeTestEntity(long id) {
CriteriaDelete<TestEntity> cd = cb
.createCriteriaDelete(TestEntity.class);
Root<TestEntity> root = cd.from(TestEntity.class);
cd.where(cb.equal(root.get(TestEntity_.id), id));
em.createQuery(cd).executeUpdate();
}
Code:
@NamedNativeQueries({ @NamedNativeQuery(name = "@SQL_DELETE_TEST_ENTITY", query = "DELETE FROM test_entity WHERE id = :id") })
public void removeTestEntity(long id) {
Query q = em.createNamedQuery("@SQL_DELETE_TEST_ENTITY");
q.setParameter("id", id);
q.executeUpdate();
}}
Below is the config I'm using:
Code:
<!-- Properties for Hibernate -->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.jdbc.batch_size" value="100" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.cache.use_second_level_cache"
value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<!-- Properties for Hibernate Search -->
<!-- Define Lucene version -->
<property name="hibernate.search.lucene_version" value="LUCENE_CURRENT" />
<!-- appropriate directory provider -->
<property name="hibernate.search.default.directory_provider"
value="filesystem" />
<!-- local master location -->
<property name="hibernate.search.default.indexBase" value="/opt/wildfly/luceneIndex" />
<!-- We don't need synchronous index updates - speed is not that important
to us -->
<property name="hibernate.search.default.worker.execution"
value="async" />
<!-- Enable statistics MBean -->
<property name="hibernate.search.jmx_enabled" value="true" />