-->
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.  [ 5 posts ] 
Author Message
 Post subject: Associoations
PostPosted: Thu Apr 06, 2006 5:57 am 
Newbie

Joined: Fri Mar 31, 2006 11:49 am
Posts: 9
Hi everyone :)
I have a question:
these are my maooing files:
First:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="IpoCredit.Rating, IpoCredit" table="rating">
        <id name="Id" column="id" type="Int32">
            <generator class="identity" />
        </id>
        <property name="StrRatingName" column="ratingname" type="String" />
        <property name="Position" column="position" type="Int32" />
        <set name="RatingOnDate" lazy="true" cascade="save-update">
            <key column="ratingid" />
            <one-to-many class="IpoCredit.RatingDate, IpoCredit" />
        </set>
    </class>
</hibernate-mapping>

Second:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="IpoCredit.RatingDate, IpoCredit" table="ratingdate">
      <id name="Id" column="id" type="Int32">
         <generator class="identity"/>
      </id>
      <property name="RatingId" column="ratingid" type="Int32"/>
      <property name="RateDate" column="date" type="DateTime"/>
      <set name="RateValue" lazy="true" cascade="all">
          <key column="ratingdateid"/>
          <one-to-many class="IpoCredit.RatingValue, IpoCredit"/>
      </set>
   </class>
</hibernate-mapping>

And third:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="IpoCredit.RatingValue, IpoCredit" table="ratingvalue">
        <id name="Id" column="id" type="Int32">
            <generator class="identity"/>
        </id>
        <property name="Amount" column="value" type="Int32"/>
        <many-to-one name="Banks" class="IpoCredit.IBank, IpoCredit" column="bankid" cascade="all"/>
    </class>
</hibernate-mapping>


From m,y ASP code i need to reach to the third object RateValue through the first object Rating. How can I do it? :) Please show me some code :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 6:25 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Which object *specifically* are you wanting to retreive? Since Rating.RatingOnDate is a collection of RatingOnDate objects and each RatingOnDate object's RatingValue is a collection of RatingValue objects.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 6:56 am 
Newbie

Joined: Fri Mar 31, 2006 11:49 am
Posts: 9
I need all RateValue object from specific Rating:)
something Like this (It's just a model): Rating.RatingOnDate[0].RateValue

Will you help me,m please?:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 8:02 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Well, in fact your model is correct: myRating.RatingOnDate[0].RateValue will return the collection of RateValue objects.

You could loop through all of the RateValue objects using a foreach, for example:

Code:
foreach(RateValue rv in myRating.RatingOnDate[0].RateValue)
{
    //Do Something
}



This would return only the RateValue objects for the first RatingOnDate object...if you wanted to get ALL RateValue objects then you'd need a nested for loop.

If you want to do this with HQL then it's a different story:

Code:
SELECT rv FROM Rating r LEFT JOIN r.RatingOnDate rod LEFT JOIN rod.RateValue rv WHERE size(rod.RateValue) > 0 AND r.Id = :Id


This would simply return all the RatingValue objects associated with the Rating objects that match the criteria in the WHERE clause.

Does that help? I'm not really sure what you're after...

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 1:37 pm 
Newbie

Joined: Fri Mar 31, 2006 11:49 am
Posts: 9
Thanks a lot:)
This loop is exactly thing I need :)
Everthing is great :)


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