public class A {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "bid", nullable = false)
@IndexedEmbedded(includePaths = {"field1", "field2");
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW,
derivedFrom = {
@ObjectPath({
@PropertyValue(propertyName = "b"),
@PropertyValue(propertyName = "field2")})
}
)
private B b;
}
public class B {
...
@KeywordField(normalizer = Constants.NORMALIZER_LOWERCASE)
@GenericField(name = "field2_sort", sortable = Sortable.YES)
private String field2
}
I want to reindex the object A only when the value of field2 of object B is modified but i get an error “HSEARCH700030: Unable to resolve dependencies of a derived property: there is a cyclic dependency starting from type”.
The mapping here looks a bit contradicting . Meaning there’s reindexOnUpdate = ReindexOnUpdate.SHALLOW (see the part starting with “Only shallow changes to a book’s category …” in particular). But at the same time, you’d want to update affected As when some B is changed…
To update As when some B is changed you’d need to have the inverse side of the association (meaning you’d need to have a collection of A in B). But I suspect that the shallow reindexing, and no inverse side of the association is there on purpose … so you wouldn’t be able to have it both ways …
Consider that B is updated by a different form than A. Updating is a fairly rare process. And I want when a particular field(field2) is changed from B only then to reindex A as it affects it. I wouldn’t want to use oneToMany relations on the B side.
Should I massindexer by class A when I change something in B or is there a better solution?
If you want to reindex A when B change, even if it’s only for some changes, then you need an association from B to A. How else would Hibernate Search know which A to reindex?
Essentially, yes. Or at least you will need to reindex manually.
There are future improvements related to your issue in the backlog, e.g. HSEARCH-1937, but as far as I know they are not being actively worked one at the moment.
Is it possible to use indexingPlan.addOrUpdate(list of object); As i see it, i need to loop the list and and do each addOrUpdate separately but for 20k records is slow.