-->
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: Single Property Mapping with Join
PostPosted: Tue Feb 26, 2008 2:03 pm 
Newbie

Joined: Tue Feb 26, 2008 1:17 pm
Posts: 9
I have tried a few different paths to solve this, but am not able to find the answer. I have 2 tables, PARTY and EMAIL. I have hibernate mappings for these tables. However, I want to create another Bean in my system, calling it PartyInfo, with a mapping that only has select columns from the PARTY, EMAIL and others joined to PARTY via a PARTY_ID. The others, I have been able to the the properties I want using the <join> method. For EMAIL though, a party can have mulitple email addresses, and I want to get only the address (the String not the Email bean) of the primary email address. We can identify the primary by a flag in the EMAIL table.

So is it possible to get this one String via a join in the mapping?

I tried something like this in the Email.hbm.xml:

Code:
<properties name="primaryEmailReference">
            <property name="isPrimary" column="IS_PRIMARY" type="true_false" length="1"/>
            <many-to-one name="party" class="com.thomson.ecommerce.rebar.model.Party">
                <column name="PARTY_ID" precision="12" scale="0" not-null="true" />
            </many-to-one>
        </properties>


and in my PartyInfo.hbm.xml:

Code:
<one-to-one name="primaryEmailAddress"
                    property-ref="primaryEmailReference">
            <formula>'T'</formula>
            <formula>PARTY_ID</formula>
        </one-to-one>


But this gets me the Email object. I need would like to have the primaryEmailAddress property be only the string from the EMAIL_ADDRESS column so I don't have to convert it later (trying keep the object size as small as possible). Any thoughts on this?

K


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 6:29 pm 
Newbie

Joined: Tue Feb 26, 2008 1:17 pm
Posts: 9
I figured out how to do this with a formula. I had tried this earlier, but was incorrectly specifying the join column. When I changed to use only table/column names and not Object/Property names, I was able to figure out the issue.

Code:
<property name="primaryEmailAddress" type="string">
            <formula>
                (select e.EMAIL_ADDRESS
                from EMAIL e
                where e.PARTY_ID = PARTY_ID
                    and e.IS_PRIMARY = 'T')
            </formula>
        </property>


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.