HSEARCH700030: Unable to resolve dependencies of a derived property: there is a cyclic dependency starting from type

Hello,

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”.

Do i need to create a new Transient field ?

    @Transient
	@IndexingDependency(derivedFrom = {
			@ObjectPath({
					@PropertyValue(propertyName = "b"),
					@PropertyValue(propertyName = "field2")})
	})
	@GenericField(sortable = Sortable.YES)
	private String bField2;

Thank you !

Hey Tony!

The mapping here looks a bit contradicting :confused:. 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 …

there is a cyclic dependency starting from type

I can’t see a cycle in the part of the mapping you’ve shared, if that’s really all the mapping and there’s no cycle but you see that error message, could you create a reproducer using this template please: hibernate-test-case-templates/search/hibernate-search-7/orm-elasticsearch at main · hibernate/hibernate-test-case-templates · GitHub
Thanks!

1 Like

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?

I found this solution but its not working.
Why @AssociationInverseSide is required when @IndexedEmbedded specified? - #5 by yrodiere

Thank you.

These two statements are contradictory.

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.

You don’t need a full-blown mass indexer for just a few entities if you know their IDs. You can use a more fine-grained solution. See Hibernate Search 7.1.1.Final: Reference Documentation

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.

1 Like

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.

What I said:

What you said:

I think we can all agree 20k records is not “just a few”.

Use the mass indexer for that.