Indexing dependency with non-indexed entity

Hello,

i would like to trigger indexation in a specific context where i index nested properties from a non-indexed object.

So for the example i will take 3 differenty Entity A B & C

here is A

@Transient
	@FullTextField(name = "myLabel", analyzer = "standard", searchable = Searchable.YES, projectable = Projectable.YES)
	@KeywordField(name = "myLabelSort", sortable = Sortable.YES)
	@IndexingDependency(
			derivedFrom = {
					@ObjectPath({@PropertyValue(propertyName = A.referenceToB)}), 
					@ObjectPath({@PropertyValue(propertyName = A.referenceToC)})
			}
	)
	public String getSearchLabel() {   ...   }

Soā€¦ when i manually index on B it trigger correctly the indexation of getSearchLabel on A (because B is @Index ) but ā€¦ when i do the same thing on C i get this :

ā€œHSEARCH700037: Cannot work on type ā€˜com.xxxx.Cā€™, because it is not indexed, neither directly nor as a contained entity in another type.ā€,

do you have any idea to rely on IndexingDependency on unindexed entities dependencies ?

Hello.

If C is contained in another type but you get an exception telling you it is not, there may be a bug.

Can you tell me what A.referenceToC is in your snippet? Also, can you provide the stack trace, and the bootstrap logs when you set the logger level to DEBUG for org.hibernate.search.mapper.pojo.mapping.building.impl.PojoMapper?

After reading your message, i realized i had no errors when hibernate start because i didnā€™t specify a specific property on my nested C Object in the IndexingDependency

@Transient
	@FullTextField(name = "myLabel", analyzer = "standard", searchable = Searchable.YES, projectable = Projectable.YES)
	@KeywordField(name = "myLabelSort", sortable = Sortable.YES)
	@IndexingDependency(
			derivedFrom = {
					@ObjectPath({@PropertyValue(propertyName = A.referenceToB)}), 
					@ObjectPath({@PropertyValue(propertyName = A.referenceToC), @PropertyValue(propertyName = C.property1)})
			}
	)
	public String getSearchLabel() {   ...   }

after upgrading my ObjectPath i have a new error when hibernate startup :

HSEARCH700020: Cannot find the inverse side of the association on type 'com.xxxxx.A' at path '.referenceToC<no value extractors>'. Hibernate Search needs this information in order to reindex 'com.xxxxx.A' when 'com.xxxxx.C' 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.xxxxx.A' when 'com.xxxxx.C' is modified, you can disable reindexing with @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO).
	at org.hibernate.search.engine.reporting.spi.RootFailureCollector.checkNoFailure(RootFailureCollector.java:50)
	at org.hibernate.search.engine.common.impl.SearchIntegrationBuilderImpl.prepareBuild(SearchIntegrationBuilderImpl.java:259)
	at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmIntegrationBooterImpl.doBootFirstPhase(HibernateOrmIntegrationBooterImpl.java:250)
	at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmIntegrationBooterImpl.bootNow(HibernateOrmIntegrationBooterImpl.java:194)

And with a
@AssociationInverseSide(inversePath = @ObjectPath({@PropertyValue(propertyName = A.referenceToC), @PropertyValue(propertyName = C.property2)}))

itā€™s working !
thanks :slight_smile:

Alright, so your initial @IndexingDependency was just telling Hibernate Search you depended on the identity of C. I can see how itā€™s confusing and maybe an exception in this case would be niceā€¦ But I suspect there are reasonable use cases for referencing just the entity, not one of its properties. Iā€™ll have to think about it.

Anyway, glad you could solve your problem :slight_smile:

1 Like