Without ReindexOnUpdate.SHALLOW drives to very bad performance

Hello, in my project i use hibernate search 6 !

@Indexed(index = "idx_name1")
@Table(name = "tableName1")
public class ObjectA {
	
	@Id
	@Column(name = "id", nullable = false, precision = 18)
    @ScaledNumberField(decimalScale = 0, sortable = Sortable.YES)
	private BigInteger id;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "objectbid", nullable = false)
	@IndexedEmbedded(includePaths = {"fielda", "fieldb", "fieldc"})
	@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
	private ObjectB objectb;
}

I want when update the objectB to update the indexes for ObjectA.
Without the use of @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) the repository.save(objectb) drives to OutOfMemory.
ObjectA with the same objectbid has over 500k records.

Can i resolve it or it could be better to reindex async later the objectA ?
Thank you !

Hello,

This is odd… With SHALLOW, repository.save(objectb) shouldn’t do anything about ObjectA.

Does ObjectB model the inverse side of the association? Because with 500k elements in the list, it probably shouldn’t, that inverse side just cannot reasonably be loaded in memory.

Regardless, do you have a reproducer? Even if it doesn’t go out of memory; something that shows ObjectA being loaded (SQL query) when calling repository.save(objectb) would already be enough to investigate.

Ok, @mbekhta pointed out to me that you wrote performance is bad “without” SHALLOW, not “with” it. I misread, sorry.

So, this is expected to perform badly. Loading 500k entities in memory can only end badly.

Your only solution at the moment would be to use SHALLOW, and to reindex ObjectA periodically to catch up on such changes. There are probably tricks you can implement, such as tracking the IDs of ObjectB instances that got modified and reindexing only the corresponding ObjectA, but that’s all going to be manual.

Long-term, Hibernate Search may make your life easier with one of the solutions listed in [HSEARCH-4956] - Hibernate JIRA ; especially [HSEARCH-1937] - Hibernate JIRA

1 Like

Thank you for your answer. For now i will use SHALLOW and i will think if it is necessary to reindex the objectA async, probably in a job !