I have two entities (entityA and entityB), one which contain another with @IndexedEmbedded, because when I search, I want to query by entityB as well, and return entityA.
The relationship (simplified) is as such:
public class EntityA {
private String name;
@OneToMany
@IndexedEmbedded
private List<EntityB> children;
}
public class EntityB {
@ManyToOne
@ContainedIn
private EntityA parent;
private String childName;
}
I am having issues now because relationally, the "children" in entityA can have up to 100k items. This causes OutOfMemory issue no matter if I am using FullTextSession.index or the MassIndexer.
I could actually remove the @OneToMany mapping in EntityA because when I want to access EntityB, I will usually do a query with some filtering and pagination, but if I remove the @OneToMany, then Hibernate Search will not index my EntityB.
Is there anyway to get the FullTextSession.index to perform indexing based on batch on the "children"?
Depending on the queries you want to effectively execute, you might be able to reverse the indexing. Instead of parking EntityA as
@Indexed
, you mark EntityB as@Indexed
and mark its parent association with@IndexedEmbedded
.That way, you won't suffer from having to load the 100k elements.
On the query side, you will need to reverse your query as well to something like
childName:Emmanuel AND parent.name:Hardy
What you will receive is EntityB instances but you can reach EntityA by simple navigation, or by using aResultTransformer
.Note that if your link between EntityB and EntityA is lazy, you can ask Hibernate Search to adjust its fetching strategy:
Criteria criteria = s.createCriteria(EntityB.class).setFetchMode("parent", FetchMode.JOIN); s.createFullTextQuery(luceneQuery).setCriteriaQuery(criteria);