-->
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 a column twice
PostPosted: Tue Mar 16, 2004 3:18 pm 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
Hi,

I have three tables:

Province
id, name

Holiday_pay_Rule
id,name

Province_Holiday_Rule
id, province_id, holiday_rule_id, value

Now, I have Province and Holiday Rule both persisted. What is the best way to map it so that I can get the values? Essentially, I need a list of rules, but I need the values associated with the rule for this province. (I will always grab the province objects and then check the rules).

I tried :
Code:
    <map
        name="holidayPayRuleValues"
        lazy="true"
        inverse="true"
        table="province_holiday_rule"
        >
       
        <key column="province_id"/>
        <index column="holiday_pay_rule_id" type="int"/>
        <element column="value" type="string"/>
    </map>

    <map
        name="holidayPayRules"
        lazy="true"
        inverse="true"
        table="province_holiday_rule"       
        >
        <key column="province_id"/>
        <index column="holiday_pay_rule_id" type="int"/>
       
        <many-to-many column="holiday_pay_rule_id" class="com.cc.tss.HolidayPayRule"/>
    </map>   


But it complains that I mapped holiday_pay_rule_id twice. Help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 3:31 pm 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
Note that the mapping twice exception occurs because of the second mapping.. i'm trying to use holiday_pay_rule as both the index and the many-to-many reference...

if I use a set instead, this works because I don't need an index.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 4:15 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
dtam wrote:
Note that the mapping twice exception occurs because of the second mapping.. i'm trying to use holiday_pay_rule as both the index and the many-to-many reference...

if I use a set instead, this works because I don't need an index.

Interesting, I don't know if it is possible to use Map collection for this mapping. Use Set, you said it works, but if you need such Map like you mapped, introduce some tricky gettter in your Persitent class that converts your persisted Set to business Map

Code:
public Map getTrickyMap()
{
    if (null == this.holidayPayRulesSet)
        return Collections.EMPTY_MAP;

    return YourTrickySet2MapConverter.convert(this.holidayPayRulesSet);
}


regards,
Leonid


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.