Hi searchers,
I revealed a use case that raise an exception with hsearch mass indexer (Cyclic dependency). Here the code :
@Entity
@Indexed
public class NatureBien extends BasicNatureBien implements ISearchableEntity, IEntityIndexed {
@OneToMany(mappedBy = Adresse_.NATURE_BIEN, cascade = {CascadeType.ALL})
@OrderColumn(name = "nature_bien_adresses_idx", nullable = false)
protected List<Adresse> adresses = new ArrayList<>();
@Transient
@GenericField(name = NatureBienIndexed_.ADRESSE_UNIQUE_CODEPOSTAL, sortable = Sortable.YES)
@IndexingDependency(
derivedFrom = {
@ObjectPath({
@PropertyValue(propertyName = NatureBien_.ADRESSES),
@PropertyValue(propertyName = Adresse_.TOPAD),
@PropertyValue(propertyName = Topad_.CODE_POSTAL)
})
}
)
public String getCodePostal() {
for (Adresse currAdresse : this.getAdresses()) {
if (currAdresse.getTopad() != null)
return currAdresse.getTopad().getCodePostal();
}
return null;
}
}
@Entity
@Indexed
public class Adresse extends BasicAdresse implements IAdresse, IEntityIndexed {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "topad_fk")
protected Topad topad;
@Transient
@AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = Topad_.ADRESSES)))
@IndexedEmbedded(name = AdresseIndexed_.TOPAD, includeEmbeddedObjectId = true, includePaths = {
ID
})
public Topad getTopad() {
return this.topad;
}
}
@Entity
public class Topad extends BasicTopad implements HasDesignationVille {
...
}
@MappedSuperclass
public abstract class BasicTopad extends BusinessObject {
protected String codePostal;
public String getCodePostal() {
return this.codePostal;
}
}
Concentrate only of the first code area. The 2 others are for context. Precisely, the line :
@PropertyValue(propertyName = Topad_.CODE_POSTAL)
implies an error with mass indexer :
Hibernate ORM mapping:
type 'com.allegoria.notariat.business.NatureBien':
path '.codePostal<no value extractors>':
failures:
- HSEARCH700030: Unable to resolve dependencies of a derived property: there is a cyclic dependency involving path '.codePostal<no value extractors>' on type 'com.allegoria.notariat.business.Topad'. A derived properties cannot be marked as derived from itself, even indirectly through other derived properties. If your model actually contains such cyclic dependency, you should consider disabling automatic reindexing, at least partially using @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO) on one of the properties in the cycle.
at org.hibernate.search.engine.reporting.spi.RootFailureCollector.checkNoFailure(RootFailureCollector.java:50)
at org.hibernate.search.engine.common.impl.SearchIntegrationBuilderImpl.prepareBuild(SearchIntegrationBuilderImpl.java:261)
at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmIntegrationBooterImpl.doBootFirstPhase(HibernateOrmIntegrationBooterImpl.java:259)
at org.hibernate.search.mapper.orm.bootstrap.spi.HibernateOrmIntegrationBooterBehavior.bootFirstPhase(HibernateOrmIntegrationBooterBehavior.java:17)
at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmIntegrationBooterImpl.lambda$bootNow$7(HibernateOrmIntegrationBooterImpl.java:218)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmIntegrationBooterImpl.bootNow(HibernateOrmIntegrationBooterImpl.java:218)
if I put something different, for instance :
@PropertyValue(propertyName = Topad_.NOM_VILLE)
The mass indexer run without error. I suppose the cyclic dependency is looking for fieldname that are equal between the one we index and the one we depend on. But the “codePostal” in topad has nothing to do with the “codePostal” in NatureBien.