I am trying to index a small portion of a rather complex Hibernate graph. My document root class has two @ManyToOne relationships. Only one of those relationships has the @IndexEmbedded annotation on it. When attempting to index my base class, using the strategy outlined in Hibernate Search in Action, I noticed that Hibernate is eagerly fetching
all related beans, not just the ones with the @IndexEmbedded annotation. This results in thousands of completely unnecessary queries to be performed that have absolutely no real impact on the indexing process.
Code:
@Entity
@Table(name = "SOMETHING")
public class TestBean implements Serializable
{
...
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "FOO_ID", insertable=false, updatable= false)
private FooBean foo;
@ManyToOne
@JoinColumn(name = "BAR_ID", insertable=false, updatable= false)
@IndexEmbedded
private BarBean bar;
...
}
My question is... is there any way to prevent Hibernate Search to only load entities that are demarcated with the @IndexEmbedded annotation rather than loading everything eagerly? I even explicitly set fetching to LAZY with no luck. I understand that people are recommending a fully hydrated graph before indexing, but I'm looking at a potential batch indexing time of 10 DAYS... uggggh
I know I could probably comment out the unnecessary relationship annotations temporarily just for the indexing, but it just seems like there could be a better way. Any help is appreciated. Thanks!