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.  [ 2 posts ] 
Author Message
 Post subject: Mapping with 2 FK referring to same PK in the other table
PostPosted: Wed Aug 16, 2006 5:22 am 
Newbie

Joined: Tue Aug 15, 2006 11:52 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1

Hello,

I am new to Hibernate and I am trying to perform this mapping.. Any advice on this...

Table User:

userid (PK)
username
.....


Table Relationship

personid,
relationid
personid (FK) refers to user(userid)
relationid(FK) refers to user(userid)
PK(personid, relationid)

Thanks in advance,

mic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:16 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
Hi,

What kind of association is it ?

For a many-to-many association, your mapping must be :
Code:
    <class name="User" table="user">
        <id name="id" type="int">
            <column name="userid" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="username" />
        </property>
   <set name="relationships" table="relationship" inverse="false" cascade="none" lazy="true">
       <key column="personid"/>
       <many-to-many column="relationid " class="User"/>
   </set>
     </class>


And your Java bean :
Code:
User {
   private int id;
   private String name;
   private Collection<User> relationships;
}


Regards,


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