Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
is it possible to do projection on objects that are part of IndexedEmbedded collection of an object?
Class Part{
@DocumentID
private Long partId;
@Field(index = Index.TOKENIZED, store = Store.YES)
private String partName;
@Field(index = Index.UN_TOKENIZED, store = Store.YES)
private Long supplierId;
}
Class Supplier{
@DocumentID
private Long supplierId;
@Field(index = Index.TOKENIZED, store = Store.YES)
private Long supplierName;
@IndexedEmbedded
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "supplierId")
private Set<Part> parts;
}
when I do qurying like this :
MultiFieldQueryParser parser = new MultiFieldQueryParser(
new String[] { "supplierId", "parts.partName" }, new StandardAnalyzer());
Query query = parser.parse("+supplierId:1 +parts.partName:AB*");
org.hibernate.search.FullTextQuery hibQuery = fullTextSession.createFullTextQuery(
query, Supplier.class);
hibQuery.setProjection("supplierId","parts.partId"); // projection
List<Object[]> result = hibQuery.list();
for (Object[] res : result) {
System.out.println("supplier id:"+((Long)res[0]).intValue());
System.out.println("Part Id :"+((Long)res[1]));
}
I am getting supplierId: 1
Part Id : null
isn't it possible to get values like 3 12 for parts.partId (like the way space separated ids shown by Index viewer tool Luke ) ? is there any other way to implement this ? I know about querying from the Part end but that approach is not feasible in my case as my domain model is complex.