-->
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.  [ 4 posts ] 
Author Message
 Post subject: mapping two key columns for a set
PostPosted: Sun Aug 05, 2007 6:19 pm 
Newbie

Joined: Sun Jul 29, 2007 3:34 pm
Posts: 3
Hi,

Can I map two foreign key constraints to one collection? I have a user class which has a set of friendship objects. Friendship objects have two users. I can't see this kind of example anywhere. When I try the following code, it doesn't work. Can anybody tell me the correct way of doing this?

Thank you so much for your help!!!!

Code:
    DbUser.hbm.xml
    <set name ="Friendships" table="Friendships" cascade="none">
        <key column="A" />
        <key column="B" />
        <one-to-many class="sn.Friendship,sn">
    </set>

   Friendship.cs
    public class Friendship : BaseNHibernateClass<Friendship, int>
    {
        private int _id;
        private DbUser _a;
        private DbUser _b;
        .............

    DbUser.cs
    public class DbUser : BaseNHibernateClass<DbUser, Guid>
    {
        private Guid _id;
        private string _name;
        private ISet<Friendship> _friendships;
        .............


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 6:55 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
Two comments:

First, if there is a relationship between DBUser and Friendship, then map that relationship. Use the ID of the Friendship to make the join. I think the properties of Friendship are irrelvant (so far as the collection mapping is concerned).

Code:
<set name="Friendships" ...>
  <key column="FriendshipID">
</set>



But, this data model makes my head hurt. A User has several friendships, of which is made up of two other users??

So, John has a friendship with (Sally / Jane) and (John / Tim)??

Or, is it more like John has friendships with Sally, Jane, John and Tim??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 7:28 pm 
Newbie

Joined: Sun Jul 29, 2007 3:34 pm
Posts: 3
Hi, thank you for your time.

DBUser John has a friendship which contains two users. Himself and a friend.

If a Friendship object has A=John and B=Jane, then I want this friendship to be in both John's collection and B's collection. So when I go John.Friendships, it should contain this friendship object. And when I go Jane.Friendship, it should also contain the same friendship object.

Is there a good way to map this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 7:51 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
intbos-tech wrote:
Is there a good way to map this?


On user look at a many-to-many set. Look at the docks for the many-to-many section. Your table design is already set up for it. This will remove the intermediate object and instead give you a list of all friends for John instead of having to look through "friendships".


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