Hello,
We are using Hibernate Search (Hibernate 4.3.7 and Hibernate Search 4.5.1) in our system and we're using MassIndexer in order to initialize the index.
Our model looks approximately like this:
Code:
@Entity
@AccessType(AccessType.FIELD)
@Indexed
public class A {
@Id
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@IndexedEmbedded(includePaths = "id", indexNullAs = IndexedEmbedded.DEFAULT_NULL_TOKEN)
private B b;
}
@Entity
@AccessType(AccessType.FIELD)
public class B {
@Id
private Long id;
private String name;
}
The problem is that when the index is being initialized, objects of class B are being fetched from the database although we need only an id from them in this case. Because of having to perform other actions after fetching objects of B from the database, our index initialization time increases dramatically.
What we've tried so far is doing a workaround like this
Code:
@ManyToOne(fetch = FetchType.LAZY)
@Field(index = Index.NO, bridge = @FieldBridge(impl = FieldBridgeImpl.class))
private B b;
@Field
public Long getBId() {
return b != null ? b.getId() : null;
}
but that didn't seem to help.
The javadoc of MassIndexer says that 'all indexed entities and their indexedEmbedded properties are scrolled from database'. So my question is - is there any way of stopping the indexer from querying the database in case we require only an id from an object (or even nothing at all if we just have to know whether it's null or not)? Or am I missing something here?