-->
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.  [ 4 posts ] 
Author Message
 Post subject: [Hibernate Search] - Projections in a ManyToOne relation
PostPosted: Mon Oct 11, 2010 11:54 pm 
Newbie

Joined: Wed Sep 08, 2010 9:58 am
Posts: 6
Location: Sao Paulo | Brazil
Good evening Srs!,

In short, I have this Entities:

PRODUCT
Code:
@Entity
@Indexed
public class Product {
    @Id
    @DocumentId
    private Long id;

    @ManyToOne
    @JoinColumn(name="idStore")
    @Field(store=Store.YES,index=Index.UN_TOKENIZED)
    @FieldBridge(impl=BridgeStore.class)
    private Store store;
    //getters and setters
}



STORE
Code:
@Entity
public class Store {
    @Id
    Long idStore;
    String nameStore;
    //getters and setters
}



BRIDGE STORE
Code:
public class BridgeStore implements FieldBridge {
    @Override
    public void set(String name, Object oStore, Document document, LuceneOptions luceneOptions) {
        Store store = (Store) oStore;
        luceneOptions.addFieldToDocument("idStore",store.getIdStore().toString(),document);
        luceneOptions.addFieldToDocument("nameStore",store.getNameStore().toString(),document);
    }

}



And this is my FullTextQuery:
Code:
    FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery, Product.class);
    query.setProjection("id", "nameStore"); //I already tried "store.nameStore"


id: That's ok!
nameStore: Always null


I tried implement TwoWayStringBridge, but did not work.


Am I doing something wrong?

Thank you very much.

Att,
Rondon


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] - Projections in a ManyToOne relation
PostPosted: Tue Oct 12, 2010 1:20 pm 
Newbie

Joined: Wed Sep 08, 2010 9:58 am
Posts: 6
Location: Sao Paulo | Brazil
Hey guys, I got it!

Instead of use "@Field & @FieldBridge" at the "Store store" attribute, I just put "@IndexedEmbedded" and, in the Store entity, I mapped with "@Field" the "idStore" and "nameStore".

Thanks anyway!

Regards,
Wrondon


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] - Projections in a ManyToOne relation
PostPosted: Tue Oct 12, 2010 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Wrondon,
yes using IndexedEmbedded seems a better fit for your problem; still to clarify the original issue:
Projection is meant to convert the document fields back in their object form, so to "restore" Store you would need a TwoWayStringBridge and you wouldn't return the properties but the Store sa a single object.

To just return the values from the index, i.e. reading the "idStore" and "nameStore" you defined in your bridge, you could use
Code:
.setProjection(ProjectionConstants.DOCUMENT);

so that the results return Lucene's Document, this has an API similar to a Map and contains the values for both idStore and nameStore.

Cheers,

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] - Projections in a ManyToOne relation
PostPosted: Wed Oct 13, 2010 12:17 pm 
Newbie

Joined: Wed Sep 08, 2010 9:58 am
Posts: 6
Location: Sao Paulo | Brazil
Hi Grinovero!

Thank you very much for the reply!

Best Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.