-->
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.  [ 1 post ] 
Author Message
 Post subject: Multiple one-to-many relations
PostPosted: Sat Jun 13, 2009 11:02 am 
Newbie

Joined: Sat Jun 13, 2009 10:52 am
Posts: 1
I have very simple object structure for Person's and their marriage relations. I have exactly same structure in the db as well. (The code is in C# but you can ignore that)

Code:
public class Person
{
    public string Id { get; set; }
    public ISet<MarriageRelation> MarriageRelations { get; set; }
}
public class MarriageRelation
{
    internal int Id { get; set; }
    public Person FirstPartner { get; set; }
    public Person SecondPartner { get; set; }
    public DateTime? MarriageDate { get; set; }
}


I'm having trouble for defining mapping for the MarriageRelation class. I couldn't use many-to-many because of additional fields of the relation (in reality there are more fields, this is simplified view).

Code:
<class name="Person, MyLibrary">
  <id name="Id" column="ID" type="String">
    <generator class="assigned" />
  </id>
  <set name="MarriageRelations" cascade="all">
    <key column="FirstPartner" />
    <one-to-many class="MarriageRelation, MyLibrary" />
  </set>
</class>
<class name="MarriageRelation, MyLibrary">
  <id name="Id" column="ID" type="Int32" >
    <generator class="native" />
  </id>
  <property name="MarriageDate" />
  <many-to-one class="Person, MyLibrary" name="FirstPartner" />
  <many-to-one class="Person, MyLibrary" name="SecondPartner" />
</class>


There are at least two problems:
- How can I map Person.MarriageRelations so that if Person can be FirstPartner or SecondPartner in the relation.
- Everytime I add a new marriage, nhibernate makes an insert (correctly) and then an update which sets the secondpartner same with firstpartner.

Any suggestions to make this work (or model this relation in a different way)?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.