I've a Spring application, using Hibernate, and connected to Elasticsearch through Hibernate-Search.
To simplify the example, I'll put only required annotations and code.
I've an entity A, contained in multiple B entities (a lot, actually ~8000).
The B entities also contains a lot of embedded details (entities C, E, ...).
Those entities are all connected with @IndexedEmbedded and @ContainedIn Hibernate-Search annotations (see the example below).
I've created a service, modifying a field of A object, and forcing the flush through flushToIndexes.
On the flush, Hibernate-Search updates A index, and because of the @ContainedIn, propagates on the 8000 B indexes.
But to update B indexes, for some reason, Hibernate-Search loads every 8000 B objects linked to the A object at one time,
and also every details contained in thoses B objects (C, E, and so on).
All this takes a long time, and ends on nothing more than java.lang.OutOfMemoryError: Java heap space.
@Entity
@Table(name = "A")
@Indexed
public class A {
@ContainedIn
@OneToMany(fetch = FetchType.LAZY, mappedBy = "a")
private Set<B> bCollection;
@Field
@Column(name = "SOME_FIELD")
private String someField; // Value updated in the service
}
@Entity
@Table(name = "B")
@Indexed
public class B {
@IndexedEmbedded
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "A_ID")
private A a;
@IndexedEmbedded
@OneToOne(fetch = FetchType.LAZY, mappedBy = "b")
@Fetch(FetchMode.JOIN)
private C c; // Some other details
@IndexedEmbedded
@OneToMany(fetch = FetchType.LAZY, mappedBy = "b")
private Set<E> eCollection; // Some other details
}
// My service
aObject.setSomeField("some value");
fullTextSession.flushToIndexes();
Increasing JVM allocated memory (from 8GB to 24 GB, which is actually a lot for ~10000 objects) didn't solve anything. So I presume the loading of the whole dataset requires more than 24 GB...
However, the problem seems more complicated than it looks ~
Is that a bug ? Is that common ? What did I do wrong ? How could I solve that ?
Is there some hidden Hibernate-Search configuration, to avoid this behaviour ?