-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with projection on IndexedEmbedded Collection
PostPosted: Tue Nov 25, 2008 3:05 am 
Newbie

Joined: Wed Oct 29, 2008 5:56 am
Posts: 14
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2008 7:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

at the moment it is not possible to project on collections. Projection is supposed to be used on simple properties.

That said, I could imagine to use @Field instead of @IndexedEmbedded and provide a custom TwoWayFieldBridge for indexing the collection of parts. Using this approach projection should work. I actually haven't tried this myself.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.