-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping Question
PostPosted: Wed Aug 08, 2007 3:37 pm 
Newbie

Joined: Wed Aug 08, 2007 3:08 pm
Posts: 4
Mapping question from newbee,

I have the following interest rate table (note: a tier is associated with a min balance);

    COMPANY TIER EFFECTIVE_DATE THROUGH_DATE INTEREST_RATE YIELD
    902 1 7/9/2007 7/15/2007 0.00 0.00
    902 2 7/9/2007 7/15/2007 1.82 0.00
    902 3 7/9/2007 7/15/2007 2.32 0.00
    902 1 7/16/2007 7/22/2007 0.00 0.00
    902 2 7/16/2007 7/22/2007 1.82 0.00
    902 3 7/16/2007 7/22/2007 2.32 0.00
    902 1 7/23/2007 7/29/2007 0.00 0.00
    902 2 7/23/2007 7/29/2007 1.82 0.00
    902 3 7/23/2007 7/29/2007 2.32 0.00


I have successfully mapped an InterrestRate class to an individual row with this mapping;

Code:
<class name="InterestRate" table="INTEREST_TIERS" >
        <composite-id>
            <key-property name="companyId" column="COMPANY" />
            <key-property name="tier" column="TIER" />
            <key-property name="effectiveDate" column="EFFECTIVE_DATE" type="date"/>
        </composite-id>   
        <property name="throughDate" column="THROUGH_DATE" type="date"/>
        <property name="interestRate" column="INTEREST_RATE"/>
        <property name="yield" column="YIELD"/>
</class>


I now want to create a class MonthlyInterestRates that contains a List of InterestRate objects so I can handle the 3 tiers as one persistent object.

Java Code For MonthlyInterestRates....

Code:
public class MonthlyInterestRate implements java.io.Serializable {

    private String companyId;
    private Date effectiveDate;
    private List interestRateTiers;  //list of InterestRate objects
    ....
    ...
}


I have having a difficult time in figuring out how to map this, any ideas?
The way I would want this to work would be that when I save the MonthlyInterestRate object, the 3 database rows would appear in the database.

Thanks,
Marty


Top
 Profile  
 
 Post subject: use bag
PostPosted: Thu Aug 09, 2007 12:39 am 
Newbie

Joined: Wed Aug 08, 2007 11:44 pm
Posts: 4
Location: Denver
Use bag mapping. so when you save Monthly Interest rates it also saves Interest rates.

_________________
Sreedhar Racharla
Programmer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 3:22 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Maybe Something similar to the the following:

Code:
<class name="InterestRate" table="INTEREST_TIERS" >
        <composite-id>
            <key-property name="companyId" column="COMPANY" />
            <key-property name="tier" column="TIER" />
            <key-property name="effectiveDate" column="EFFECTIVE_DATE" type="date"/>
        </composite-id>   
        <property name="throughDate" column="THROUGH_DATE" type="date"/>
        <property name="interestRate" column="INTEREST_RATE"/>
        <property name="yield" column="YIELD"/>
        <many-to-one name="monthlyinterestrate"
            insert="false"
            update="false"
            not-null="true">
        <column name="companyId"/>
        <column name="effectivedate"/>
        </many-to-one>
</class>

<class name="MonthlyInterestRate" table="monthlyinterestrate" lazy="true">
   
    <composite-id>
        <key-property name="companyId"/>
        <key-property name="effectivedate"/>
    </composite-id>
               
    <bag name="interestratetiers"
            fetch="join"
            inverse="true"
            cascade="save-update">
        <key>
            <column name="companyId"/>
            <column name="effectivedate"/>
        </key>
        <one-to-many class="InterestRate"/>
    </bag>
   
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 11:30 am 
Newbie

Joined: Wed Aug 08, 2007 3:08 pm
Posts: 4
Thank you very much for your reply.
There is one issue though. there is no monthlyinterestrate table in the legacy database. The MonthlyInterestRate object is an encapsulation of the three InterestRate records. Is that possible? Any Ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 2:38 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Hi,
I am not sure if I understand it correctly, but how would you than keep track of MonthlyInterestRate data? I mean where do you keep the relationship between companyID's and interestRateTiers values? I assume there needs to be a table that keeps track of the relationship between sets of interest rates and their companyId. To give an example:

Code:
<hibernate-mapping package="eg">

    <class
        name="user"
        table="user">

        <id name="id"  column="user_ID">
            <generator class="native"/>
        </id>

        <property name="name" column="NAME" not-null="true"
            unique="true"/>

        <bag name="interestRateTiers" inverse="true" cascade="all">
            <key column="user_ID"/>
            <one-to-many class="InterestRate"/>
        </bag>
    </class>

<class
        name="InterestRate" table="InterestRate"
        dynamic-update="true">

        <composite-id>
            <key-property name="companyId" column="COMPANY" />
            <key-property name="tier" column="TIER" />
            <key-property name="effectiveDate" column="EFFECTIVE_DATE" type="date"/>
        </composite-id>

        <property name="throughDate" column="THROUGH_DATE" type="date"/>
        <property name="interestRate" column="INTEREST_RATE"/>
        <property name="yield" column="YIELD"/>

        <many-to-one
            name="user"
            column="user_ID"
            not-null="true"/>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 12:48 pm 
Newbie

Joined: Wed Aug 08, 2007 3:08 pm
Posts: 4
The relationship is stored in the same table. The table layout and sample data are in the initial post above. In this case both objects come from the same (legacy) table. In the sample data above there is only one company shown (902). The data shows that for each month there is a new set of tiered interest rates entered. From an object oriented perspective the monthly object contains a collection of interest rates keyed by tier.


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