-->
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: One-to-many associations
PostPosted: Fri Mar 31, 2006 12:00 pm 
Newbie

Joined: Fri Mar 31, 2006 11:49 am
Posts: 9
HI every one!
Is anybody can help me with such kind of problem:
these are my mapping files:

1.For class Rating:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="IpoCredit.DBClasses.Rating, IpoCredit" table="rating">
        <id name="Id" column="id" type="integer">
            <generator class="identity" />
        </id>
        <property name="StrRatingName" column="ratingname" type="String" />
        <property name="Position" column="position" type="integer" />
        <set name="RatingOnDate" inverse="true" lazy="true" cascade="save-update">
            <key column="ratingid" />
            <one-to-many class="IpoCredit.DBClasses.RatingDate, IpoCredit" />
        </set>
    </class>
</hibernate-mapping>

2. For class RatingDate:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="IpoCredit.DBClasses.RatingDate, IpoCredit" table="ratingdate">
      <id name="Id" column="Id" type="integer">
         <generator class="identity" />
      </id>
      <property name="RatingId" column="ratingid" type="integer"/>
      <property name="RateDate" column="date" type="DateTime"/>
      <set name="RateValue" inverse="true" cascade="save-update">
          <key column="RatingDateId"/>
          <one-to-many class="IpoCredit.DBClasses.RatingValue, IpoCredit"/>
      </set>
   </class>
</hibernate-mapping>

3. For class RatingValue:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="IpoCredit.DBClasses.RatingValue, IpoCredit" table="ratingvalue">
      <id name="Id" column="Id" type="integer">
         <generator class="identity" />
      </id>
      <property name="RatingDateId" column="ratingdateid" type="integer"/>
      <property name="BankId" column="bankid" type="integer"/>
      <property name="Amount" column="value" type="integer"/>
   </class>
</hibernate-mapping>


Every mapping file contains the decription of one-to-many associations.
My C# code:
Code:
         public static IList getAllRatings(ISession session)
      {
         IList ratings = session.Find("from Rating");
         return ratings;
      }


Where i'm trying to execute the code above, i'm getting a mictake:
Here:
Code:
IList ratings = session.Find("from Rating");


Mistake: Specified cast is not valid.
Please Help me! It's very important.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 12:18 pm 
Newbie

Joined: Wed Mar 22, 2006 12:52 pm
Posts: 5
The error you're probably getting likely involves the code files, so you should post those as well.

I also noticed something else: You have both of your 1:n relations defined as "inverse=true". This tells NHibernate that the other side will be taking care of maintaining the relation. You do not have this defined for either RatingDate or RatingValue.

For example, for RatingDate, you should add

<many-to-one name="Rating" column="ratingid"/>

Also, you need to add a property to your RatingDate class called "Rating" of type Rating.

Do this for RatingValue as well.


Note that because you have the object reference, having the ratingid property is completely unnecessary unless it's required in your domain model (and that is usually not a good design decision)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 5:05 am 
Newbie

Joined: Fri Mar 31, 2006 11:49 am
Posts: 9
Thanks a lot for your help :)
I found the right way to soolve mu problem.

But now I have another question :)
How to bind with DataGrid I know:) It's easy :)
I need to bind data from my objects (NHibernate), to DataSet. I need such thing to get the ability to do In-Place Editing in my DataGrid. All exmaples and samples posted on many sites describing exactly this method of realization. But to do In-Place Edit I need to operate woth DataSet :)
So can you help me, and post some code may be, that shows how to bind data with DataSet inHibernate context?:)

Or is there any other way to do In-Place Editing?:)


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.