-->
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.  [ 3 posts ] 
Author Message
 Post subject: mapping search for composite ID entities
PostPosted: Tue Mar 05, 2013 11:05 am 
Newbie

Joined: Tue Mar 05, 2013 10:50 am
Posts: 2
Hi,
I have a problem mapping entity with composite ID. Right now I'm using hibernate-search 3.4.2(would prefer to stay but don't mind upgrading if unevitable).
I have entity Execution that uses composite id(only combination of all 3 is unique in table). The id is embeded so it uses only 1 table. It is mapped using hbm.xml file:
Code:
<class name="com.myApp.model.Execution" table="EXECS" lazy="true">
        <composite-id name="execId" class="com.myApp.model.ExecutionPK">
            <key-property name="id" type="string" length="128"/>
            <key-property name="execDate" type="date"/>
            <key-property name="sourceSystem" type="string" length="128"/>
        </composite-id>
        <property name="rootId" type="string" length="128" />
        <property name="accountID" type="string" length="128" index="idxExecAccountId"/>
</class>

What would be the correct mapping of the id if I need to be able to search by execDate(bridged by DAY)?

Documentation is not really clear in this. One of solutions would be to create a getter in Execution:
Code:
@Field(index = Index.UN_TOKENIZED, store = Store.YES)
    @DateBridge(resolution = Resolution.DAY)
    public Date getExecDate() {
        return execId.getExecDate();
    }


But how do I tell hibernate-search that private ExecutionPK execId; is ID? It doesn't know how to map iot back and forth. I guess I could use custom bridge(use smt like id.toString+execDate.toString()+sourceSystem.toString()) but how does hibernate-search then select this entity from DB if its composed key of 3 fields? Is there smt like bidirectional bridge?
Tried google but no luck so far. Documentation mentions how to map embedded entities but not how to deal with it if its composed PK.

Thanks
J.


Top
 Profile  
 
 Post subject: Re: mapping search for composite ID entities
PostPosted: Tue Mar 05, 2013 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
But how do I tell hibernate-search that private ExecutionPK execId; is ID? It doesn't know how to map iot back and forth. I guess I could use custom bridge(use smt like id.toString+execDate.toString()+sourceSystem.toString()) but how does hibernate-search then select this entity from DB if its composed key of 3 fields? Is there smt like bidirectional bridge?


Yes exactly.
This is called TwoWayFieldBridge and is documented in section 4.4.3.1.3. Two-way bridge
http://docs.jboss.org/hibernate/search/4.2/reference/en-US/html_single/#d0e4130

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


Top
 Profile  
 
 Post subject: Re: mapping search for composite ID entities
PostPosted: Wed Mar 06, 2013 4:23 am 
Newbie

Joined: Tue Mar 05, 2013 10:50 am
Posts: 2
Cool this is exactly it! Many thanks.


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