Hello,
In my case, I have the following ORM mapping:
@Entity
public class Acte extends BasicActe implements Comparable<Acte>, HasToSynchronizeSRC {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "type_acte_fk")
protected TypeActe typeActe;
@IndexedEmbedded(includePaths = { TypeActe_.LIBELLE})
public TypeActe getTypeActe() {
return this.typeActe;
}
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class TypeActe extends BasicTypeActe implements AffectationModeleItf {
//Nothing in relation with depot
}
So when I want to create the indexes, it failed with :
failures:
- HSEARCH700020: Unable to find the inverse side of the association on type 'com.allegoria.notariat.business.Acte' at path '.typeActe<no value extractors>'. Hibernate Search needs this information in order to reindex 'com.allegoria.notariat.business.Acte' when 'com.allegoria.notariat.business.TypeActe' is modified. You can solve this error by defining the inverse side of this association, either with annotations specific to your integration (@OneToMany(mappedBy = ...) in Hibernate ORM) or with the Hibernate Search @AssociationInverseSide annotation. Alternatively, if you do not need to reindex 'com.allegoria.notariat.business.Acte' when 'com.allegoria.notariat.business.TypeActe' is modified, you can disable automatic reindexing with @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW).
My analysis :
Acte class can have a foreign key to TypeActe, but the inverse is not mandatory in ORM mapping. Why Hibernate Search force me to do so ?
If I don’t put the annotation HSearch is expecting, ie @AssociationInverseSide, it means that HSearch don’t know on which property this property relies on so to update this latter, and then reindex (partially ?) this document (Acte entity) to keep information up to date.
Two ways for solution :
- Either I had the other side mapping with :
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class TypeActe extends BasicTypeActe implements AffectationModeleItf {
@OneToMany(mappedBy = Acte_.TYPE_ACTE)
private Set<Acte> actes;
//getter+setter
}
- Or I explicitly say I don’t care to trigger a reindex of this document when this property change with :
@IndexedEmbedded(includePaths = { TypeActe_.LIBELLE})
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)
public TypeActe getTypeActe() {
return this.typeActe;
}
In first case, from TypeActe, we never do any process on the acte(s) it belongs to, so the document should never be reindex based on “typeActe” property (updated or not).
In Second case, I’am confused because, I want to reindex my document when typeActe is changing (the includePaths = { TypeActe_.LIBELLE}
may change because the foreign key has changed) , whereas I say the contrary with reindexOnUpdate = ReindexOnUpdate.NO
At the basis, I simply never put the annotation @IndexingDependency
thinking that typeActe is a property belonging to Acte, the same like any another ORM-mapped property, when it changes, I want my document to be reindexed.
Thanks for some clarification.