Changing a child property, not updating indexes in Parent

Hello,
i have 2 classes, ObjectA and ObjectB.

public class ObjectA {
    @ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "objectBid")
	@IndexedEmbedded(includePaths = {"id", "descr", "descr_sort"})
	@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
	private ObjectB objectB;
}

public class ObjectB {
    @Column(name = "descr", length = 100)
	@FullTextField
	@GenericField(name = "descr_sort", sortable = Sortable.YES)
	private String descr;
}

1st scenario:
Steps

  1. Change the descr of objectB

  2. Update objectA

  3. All indexes updated successfully

  4. Searching with the new descr and all works fine

2nd scenario:
Steps

  1. Change the descr of objectB

  2. Searching with the new descr

  3. The indexes is not updated and i cant search with the new descr.

How can i update indexes either changing the objectA or the objectB?

Thank you !

Hey Tony,

The behaviour you are describing is exactly how ReindexOnUpdate.SHALLOW should behave (see ReindexOnUpdate.SHALLOW).

To get the index of ObjectA to be updated when you only changed an ObjectB you would need to remove the @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW).
If, after you do that, you’ll get an exception like "Unable to find the inverse side of the association on type … ". You’ll have to specify the inverse side of the relation in ObjectB:

public class ObjectB {
    // ... 
    @OneToMany(mappedBy="objectB")
    private Set<ObjectA> objectAs;
}
1 Like

Thank you ! :slight_smile: Removing the @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) will have i performance issues for milliion records ?

Hard to say without knowing your data… if a single objectB is linked to a million of objectAs and you have frequent updates to objectB then yes…
Depending on your business needs you may be able to leave the model as it was, and do consider updating the index in some time-intervals, for that see this section on using indexing plans.