@Documented @Target(value={METHOD,FIELD}) @Retention(value=RUNTIME) public @interface IndexingDependency
This annotation is generally not needed, as the default behavior is to consider all properties that are actually used in the indexing process as dependencies that trigger reindexing when they are updated. However, there are some reasons that could justify ignoring a dependency, in which case this annotation is necessary.
In particular, some properties might be updated very frequently, or trigger reindexing to other entities that are very expensive to load in memory.
See for example this model:
@Indexed
public class EntityA {
@IndexedEmbedded
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
// + some annotations defining "EntityB.a" as the inverse side of this association
private EntityB b;
}
public class EntityB {
private List<EntityA> a; // This is a very big list
@GenericField
private String field;
}
Entity A is indexed and embeds entity B.
But the link back from entity B to entity A is a list that might contain a lot of elements,
so we don't want to load this list every time EntityB#field
is updated:
the @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
annotation prevents that.
This means in particular that updates to EntityB#field
need to be taken into account through some external process.
One solution would be to reindex every night in a batch process, for example,
which would mean allowing the index to be partly out-of-date for at most 24 hours.Modifier and Type | Optional Element and Description |
---|---|
ObjectPath[] |
derivedFrom |
ContainerValueExtractorBeanReference[] |
extractors |
ReindexOnUpdate |
reindexOnUpdate |
public abstract ReindexOnUpdate reindexOnUpdate
public abstract ObjectPath[] derivedFrom
public abstract ContainerValueExtractorBeanReference[] extractors
Map<EntityA, EntityB>
,
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO, extractors = @ContainerValueExtractorBeanReference(type = MapKeyExtractor.class))
would mean "do not reindex the entity when map keys (of type EntityA) change",
while @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO, extractors = @ContainerValueExtractorBeanReference(type = MapValueExtractor.class))
would mean "do not reindex the entity when map values (of type EntityB) change".
By default, Hibernate Search will try to apply a set of extractors for common types
(Iterable
, Collection
, Optional
, ...)
and use the first one that works.
To prevent Hibernate Search from applying any extractor, set this attribute to an empty array ({}
).Copyright © 2006-2018 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.